Introduction
In this article, we will see what are the list of commonly used commands in Git. These are the commands which are really useful while working on any project. Hope this will be useful.
1) To initialize GitHub Repository in your local machine project folder:
git init2) To get the status of files:
git status3) To configure Username and Password:
git config –global user.name “user-name”
git config –global user.email “email-id”4) To clone the repository to your local machine:
git clone URLNote: Here URL is GitHub Repository URL
5) To add a single file to GitHub:
git add file-name6) To add all the modified file to GitHub:
git add .
git add -A7) To commit the changes to GitHub:
git commit -m “commit-message”8) Get the latest code from the main branch:
git pull9) To pull the latest code from a particular branch:
git pull branch-name10) To list all the branches including local and remote:
git branch -a11) To create a new branch name:
git branch branch-name12) To delete a branch:
git branch -d branch-name13) Delete remote branch:
git push origin --delete branch-name14) To create a new branch and switch to the new branch created:
git checkout -b branch-name15) Rename branch (local):
git branch -m old-branch-name new-branch-name16) To switch a branch:
git checkout branch-name17) To discard changes of a particular file:
git checkout -- file-name.txt18) Merging branch (active branch):
git merge branch-name19) Merging to a target branch:
git merge source-branch target-branch20) Stash your changes:
git stash21) Remove stash:
git stash clear22) Show difference:
git diff source-branch target-branch23) To view the log/changes:
git log24) Detailed view of log/changes:
git log --summary25) Brief view of log/changes:
git log --online26) Get the help:
git help27) To go back to the previous commit/changes:
git reset --hard28) List stashed files:
git stash list29) Come out of stash (write working from the top of stash stack):
git stash pop30) Discard stashed changes:
git stash drop31) Going back to HEAD:
git reset --soft HEAD32) Going back to the commit before HEAD:
git reset --soft HEAD^33) Equivalent to "^":
git reset --soft HEAD~134) Going back two commits before HEAD:
git reset --soft HEAD~235) To see the list of available tags:
git checkout v0.0.136) To set the current tag to v0.0.1:
git tag -a v0.0.3 -m “version 0.0.3”37) To create a new tag:
git push –tags38) To delete the file from your working directory:
git rm file-name39) To show the metadata and content changes of the specified commit:
git show commit-name40) To delete a branch:
git branch -d branch-name41) To delete a branch forcefully:
git branch -D branch-nameNote: This will force deletion of the branch, even if it contains unmerged/unpushed commits.
42) Search the working directory for "add()":
git grep "add()"43) List of branches:
git branch
git branch --list44) Undo the changes:
git log --oneline
git revert commit-id45) To delete a file forcefully:
git rm -rf file-nameTo get the Git version:
git --versionHow to add a project to GitHub Repository?
- Create a project on your local machine.
- Create a GitHub Repository
- Open the Git Bash go to the path where the project folder exists and type these commands,
Code
git init git remote add origin https://github.com/username/repository-name.git [Note : Make sure you are in correct repository using : git remote -v] git add . git commit -m "commit-message” git push origin master --force [provide your username and password] - Now go to GitHub Repository and check your Repository.
Conclusion
In this article, we have seen the list of commonly used Git commands. Hope you find this helpful. In addition to these commands, there are a lot of other commands including different options. Comment below with the commands you frequently use. Thank you.

Venkatasubbarao PolisettyPosted Jul 28, 2021, 6:46 AM
Useful Article!
Aryan KumarPosted Jul 4, 2021, 2:58 AM
Great Work....
Gurpreet AroraPosted Jun 30, 2021, 2:02 PM
Nice article
Virender ThakurPosted Jun 29, 2021, 9:15 AM
Thank you so much. Really appreciate your efforts.
Mahesh ChandPosted Jun 29, 2021, 4:37 AM
Nicely done! Once again.