If you want to become a great developer, you need to master Git.
But Git can be confusing. With so many commands and options, it’s hard to know which ones actually matter.
In this article, I’ll walk you through the Top 20 Git Commands every developer should know.
These are the exact commands I’ve used over the past 11 years as a programmer. If you get comfortable with just these, you’ll be ready for almost anything Git throws your way.
1. git init
Turns a regular folder into a Git repository by creating a hidden .git
directory.
git init
Use this when starting a new project from scratch.
2. git config
Sets your user name and email identity for Git commits.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
3. git clone
Clones an existing repository from a remote source.
git clone https://github.com/user/repo.git
4. git remote
Manages your remote repositories.
git remote -v
git remote add origin https://github.com/user/repo.git
5. git status
Displays the current state of the working directory and staging area.
git status
6. git add
Stages files for commit.
git add filename
git add .
7. git commit
Records changes to the repository.
git commit -m "Your commit message"
git commit --amend # To modify the last commit
8. git push
Uploads local changes to the remote repository.
git push origin main
9. git pull
Fetches and merges changes from a remote branch.
git pull origin main
10. git fetch
Downloads changes from the remote repository but doesn’t apply them.
git fetch origin
11. git branch
Lists, creates, or deletes branches.
git branch
git branch new-feature
12. git checkout
Switches branches or restores files.
git checkout new-feature
git checkout -b another-feature
git checkout -- file.txt
Alternative: Use
git switch branch-name
for switching branches.
13. git merge
Merges one branch into the current branch.
git merge new-feature
14. git rebase
Reapplies commits on top of another base tip.
git rebase main
⚠️ Be cautious with rebasing public/shared branches.
15. git log
Shows commit history.
git log
git log --oneline
git log --graph --oneline
16. git diff
Shows the differences between changes.
git diff
git diff main new-feature
17. git stash
Temporarily stores changes without committing.
git stash
git stash list
git stash apply
git stash pop
18. git reset
Moves the current branch tip and optionally modifies the index and working directory.
git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1
19. git revert
Creates a new commit that undoes the changes from a previous commit.
git revert <commit-hash>
20. git cherry-pick
Applies the changes introduced by a specific commit to the current branch.
git cherry-pick <commit-hash>
Conclusion
That’s it! These 20 commands are the bread and butter of using Git effectively.
Once you’re confident using them, you’ll be able to:
- Manage branches like a pro
- Collaborate confidently on team projects
- Debug issues with ease
- Contribute to open source
Bookmark this post or save it in your notes — it’s your Git cheat sheet.
If you found this useful, share it with your dev circle and follow me for more dev tips!
Happy coding! 🚀