Top 15 Git Commands with Examples

backbench academy
5 min readJan 28, 2021


Let’s talk about the Top 15 Git Commands, that we will use regularly while working with Git.

Git Installation:

For Linux

$ sudo yum install git -y

For Ubuntu

$ sudo apt-get install git -y

For Windows

Download from this link installs with the default configuration.

Git Commands:

git config:

git-config — Get and set repository or global options.

Git Config sets the author name and email address to be used with your commits.


$ git config –global “<name>”

$ git config –global “<email address>”


git init:

git-init — Create an empty Git repository or reinitialize an existing one.

Git init creates an empty Git repository — like. git directory with subdirectories for objects, refs/heads, refs/tags, and template files.


$ git init git-demo


git clone:

git-clone — Clone a repository into a new directory

Git clone, Clones a repository into a newly created directory from the Git repository.


$ git clone <repo-URL>


git branch:

git-branch — List, create or delete branches

Git branch will list all the local branches and creating a new branch & deleting them in the current repository.


For new branch:

$ git branch <branch-name>

For listing branch:

$ git branch –list

For deleting branch:

$ git branch -d <branch-name>


git checkout:

git-checkout — Switch branches or restore working tree files

Git checkout used to move from one branch to another.


$ git checkout <your-branch-name >

Using this Git checkout command, we can create a new branch and also switches to that particular branch.


$ git checkout -b <branch-name>


git add:

git-add — Add file contents to the index

Git adds update the index (Add the files to staging area).


Add a single file:

$ git add <filename>


To add all files:

$ git add -A


git status:

git-status — Show the working tree status

With this command we can check whether it was staged, un-staged, and which files get modified or deleted.


$ git status

git commit:

git-commit — Record changes to the repository

This command used to save your changes to the local repository. A commit containing the current contents of the index and the given log message describing the changes.


$ git commit -m “your commit message”

git log:

git-log — Show commit logs

Git log is used to read a history of everything that happens to a repository, and log contains commit hash, commit author metadata, commit date metadata, commit message.


$ git log

git rm:

git-rm — Remove files from the working tree and from the index

Git rm command will remove the file from the repository. The git rm command removes the file not only from the repository but also from the staging area.


$ git rm <filename>

git stash:

git-stash — Stash the changes in a dirty working directory away

Git stash temporarily saves your data safely without committing, some options of git stash — Git stash save, Git stash list, Git stash clear, etc…,


$ git stash

git push:

git-push — Update remote refs along with associated objects

It will push your local changes to remote repository, after committing changes locally.


$ git push <remote-URL> <branch-name>


$ git push -u origin <branch-name>

git pull:

git-pull — Fetch from and integrate with another repository or a local branch

git pull command acquires the latest changes from the remote repository to the local repository, and its combination of git fetch and git merge commands.


$ git pull <remote-URL>

git revert:

git-revert — Revert some existing commits

The Git revert command is used to undo the changes to our local repository or remote repo. Just give the hash code that you want to undo the changes.

Let’s take two branches:

Branch A

Branch B

git revert B will create a commit that undoes changes in B.

git revert A will create a commit that undoes changes in A, but will not touch changes in B

Note that if changes in B are dependent on changes in A, the revert of A is not possible.


$ git revert <hash-code>


$ git log (copy the hash code)


$ git revert b0a877b


Check for git log

$ git log

git merge:

git-merge — Join two or more development histories together

Git Merge is used by git pull to incorporate changes from another repository and can be used by hand to merge changes from one branch into another.


$ git merge <branch-name>

If you want to learn more about git commands Or Start with DevOps Course. Join us at Backbench Academy.

Have joyful learning.!



backbench academy

We offer IT and Non-IT training to students and professionals who are willing to improve their skills.