Basic Git Commands A dev Should know 🐳

Saurav Aggarwal
4 min readMay 3, 2021

Git is the superpower that is needed by every developer

3W

  1. What — Git is a version control tool which means you can manage different versions of your code and can restore different changes that you made to your code during the different interval of time so it gives you superpower over the history of your code so basically, it prevents you from making different folder code and saying final, now-its-final, etc
  2. When — Git can be used for many cases and the most common case in which git is used is when you have a large team or multiple devs working and it can be used for managing as I explained different versions of code.
  3. Why — Git has so many merits that it becomes difficult not to recommend and saves a lot of time for the minor things that might cause us days of work if we do not use git.

Cloning a repo

Ok so cloning a repo is basically a programmer way of saying that downloading the source code from GitHub or any version control managing system

git clone <url_of_repo>

Making Your branch

So making a branch is a confusing term so for this, you have to understand how git works so read the header on what is git and how it sees code but for simplicity, I can say that a branch is a copy of the code at that point of time on which you can develop your features.

git checkout -b <name_of_the_branch_you_want_to_give>

Pulling a branch

Pulling from a git repo is a fancy way of saying that copy the missing bits of code present in the branch you are pulling from to the branch you currently are.

git pull <branch_name>

Pushing your branch to remote

Pushing your branch to remote is can be related to uploading your pic ton Instagram but instead, for your photo, you does this for your code and instead of Instagram it’s to your online GitHub repo you have this is one of the most important things you will do as a developer as pushing your code to the repo will lead to PR and merging and that will lead to your code being live in production.

git push#I Prefer mentioning the branch name
git push origin <branch_name>

Fetching a branch from repo

So there will be many branches that will be present on your online GitHub repo as there are different types of code the common branches are dev, production, stage, master, etc. so there might be a case when you need these branches to your local repo.

git fetch origin <branch_name>

Checking out to a branch

So if there are multiple branches in your GitHub repo you might need to switch between these branches so for this, you first need to know what branches you have so that run the following command

git branch

and for switching run

git checkout <branch_name>

Adding files to stage

Adding files to the stage is basically means keeping the files aside whose changes you want to take to in your branch or your code basically and the most common that we use is

git add <file_path>

Note: There are many more I am just covering that are widely used.

Committing your changes

so you can say this is the stage where you are sure of your changes and want to update your branch with this code so that if you push your changes the person fetching should get these changes so you can commit these changes to your branch.

git commit -m "<message_you_want_to_give>"

Note: Your changes should be in stage state before committing.

Seeing the Status of your repo

Suppose you want to check the status of your GitHub repo to see if you have some residual changes left so can just run the following command and you will know.

git status

--

--

Saurav Aggarwal

Just a curious dev who writes when gets bored of work life