Table of contents
Reading Time: 2 minutes

Git is a tool that is most widely used by the developers. Using git one can upload his/her code to the platforms like GitHub, bitbucket, GitLab etc. in form of repository and can then anyone can access the repository using the link if they have access. Git allows only public repositories to be free. In this blog I am going to discuss basic git commands that are essential for you to get started with Git whether you are an individual programmer or work in an organization. I recomment you using SourceTree or fork git client.

Git clone: You need to use this command when you want to clone any existing repository into your file system. First you need to move to the directory where you want to have the repo (perhaps using cd if you are on CLI) . process is simple: go to the directory -> type ‘git clone reponame.git’ -> hit enter and you are good to go.

Git pull: This command should be used by you if you want to fetch the recent changes from a particular branch. You need first to checkout (will come to this soon) on the working branch, and then pull the code you desire on the working branch to have the lates code.

Git add and commit: “git add” command is used to add the local changes on your system to the working branch. Syntax is simple: “git add nameofmodifiedfilewithextension” otherwise if you want to add all the changes of the current folder to the working branch you can use “git add .”. You also need to type “git init” to initialize git if you are using CLI. On the other hand “git commit” is used to save your changes (that you added using git add) on to the working branch. You can also add your message by appending -m “my message” to git commit e.g. ‘ git commit -m “updated code” ’.

git stash and merge: Git stash will allow you to save your changes secretly (used for the changes that you do not want to commit) while allowing you to only commit changes you want to commit. Merge is used to merge the changes you have made on your branch to the desired branch. Merge is usually done after raising the pull request and getting approval of the code owners usually.

Git checkout and fork: git checkout is used to switch between normal branch to working branch. The branch that you have checked-out is the working branch and all changes will be there. Fork is used when you want to contribute to someone else’s code. You fork and make changes, changes get merged after the approval of code owner.

Git rebase: If we are 1 or more commit behind, we should rebase the code (pulling the code from the desired branch (usually master) and selecting the option to “rebase instead of merge”(if you are using a VCS(version control system for example SourceTree) )