Lessons from my "Introduction to Git" Course

in , , by Wemi Ibidun, October 26, 2021
Git is a free and Open Source version control system (VCS), that is used to track changes in any file(s). It also provides the ability to roll back and maintain separate different versions of your files at the same time.  It is used for coordinating and collaboration amongst developers. Its goal is speed, support and efficiency.

I just finished a short course on Code-academy on Git and decided to document some of the important lessons and commands that I learnt. With no further ado, let's get right into it๐Ÿ‘‡

Lessons from my Git Course
- Git is a software that allows you to keep track of changes made to a project over time. Github on the other hand is popular hosting service for Git repositories. Git projects are usually managed on Github. 

- GitHub allows users to store their local Git repositories in the cloud. With GitHub, you can backup your personal files, share your code, and collaborate with others. 

-  The basic git workflow consists of 
  • Working Directory: where you’ll be doing all the work: creating, editing, deleting and organizing files
  • Staging Area: where you’ll list changes you make to the working directory
  • Repository: where Git permanently stores those changes as different versions of the project

 A commit permanently stores changes from the staging area inside the repository. 

- The Standard Conventions for commit messages is that your message(s):
  • Must be in quotation marks
  • Should be written in the present tense
  • Should be brief (50 characters or less) when using-m

- In Git, the commit you are currently on is known as the HEAD commit.

- Git allows you to create branches so that you can experiment with versions of a project. When branching, * (asterisk) shows what branch you are currently working on.

- A remote is a shared Git repository that allows multiple collaborators to work on the same Git project from different locations

- The workflow for Git collaborations typically follows this order:
    ~ Fetch and merge changes from the remote
    ~ Create a branch to work on a new project feature
    ~ Develop the feature on your branch and commit your work
    ~ Fetch and merge from the remote again (in case new commits were made while you were working)
    ~ Push your branch up to the remote for review

Important Git Commands to know

Git CommandMeaning
git initThe word init means initialize. The command sets up all the tools Git needs to begin tracking changes made to the project.
git statusThis is used to check the changes you make to your working directory
git add filename or git add .This is used to add a file to your staging area
git commit -m "type your commit message here"This is how to commit (a commit stores changes from the staging area inside the repository)
git revert commitidCommand to revert commit changes
git diff filenameThis command is used to see the differences as it appears in the working directory vs. how it appears in your last commit.
git logOften with Git, you’ll need to refer back to an earlier version of a project. Commits are stored chronologically in the repository and can be viewed with git log
git reset HEAD filenameThis command can be used to unstage a file from a staging area
git merge branch_nameUsed to combine two branches together
git branch -d branch_nameThis is how to delete a branch
git branchThis command will list all the branches that you have
git branch new_branch_nameThis command is create a new branch (branch name cannot contain whitespaces) 
git fetchUsed to check if changes have been made to the remote and brings the changes down to your local repository (local branch)
git checkout branch_nameThis is used to switch to a branch. Once you switch branches, you will now be able to make commits on the branch which will have no impact on master
git checkout -This command is used to switch to the branch last checked out
git push origin branch_nameUsed to push your branch to the remote
git pull origin branch_nameThis command id used to pull the latest changes from the remote repository into the local repository.
git clone repository urlThis is the command to create a clone (replica of a project on your local directory)
git remote -vUsed to view a list of Git's project remotes

Get Started with Git in 10 Steps

Step 1: Download git (https://git-scm.com/book/en/v2/Getting-Started-Installing-Git). This link contains the details on how to download git and the steps to take.

Step 2: Verify git is installed by typing git --version in the command line

Step 3: On your computer, create a new folder for a project

Step 4: On your command line, change your directory to the newly created folder and add a local git repository with git init

Step 5: Create a new file in the folder and add some code to it

Step 6: Stage the file with git add filename

Step 7: Commit the file with git commit -m "type your commit message here" 

Step 8: Everything from step 1 to 7 has been done in the local repository. If you want to push to the remote repository such as github. Create an account (if you already have, log into the account),  After logging in, create a new repository and give it a name. This will create a remote repository on Github.

Step 9: To add the local repository to the remote, use git remote add origin [repository url] 

Step 10: To push all the code from the local repository to the remote, use git push -u origin master This pushes your code from the master branch in your local repository to the master branch in the remote repository.

Once you are done with these 10 steps, you will be able to see your file on Github. You can then keep modifying, adding or even delete as you wish.

Git is a powerful open source distributed version control system that is very useful for developers to collaborate and manage their code. I hope you have been able to learn one or two things from this article. I enjoyed taking the git course and I was also able to improve my git knowledge. I decided to take the git assessment skill test on LinkedIn and I passed it as well (whoop whoop)

This will be all from today. I hope to see you soon...✌️

Food for Thought:- "You can do a lot with Git, and many of the rules of what you *should* do are not so much technical limitations but about what works well when working together with other people. So git is a powerful set of tool" ~ Linus Towalds.


SHARE 0 comments

Add your comment