Most engineers use Git every day—but only a handful of commands.
That’s fine… until something goes wrong.
A bad merge.
A wrong commit.
A force-push panic.
This list covers 20+ Git commands you’ll actually use in real projects, with one-line explanations so you know what they do and when to use them.
Core Git Commands Basics
1. git init
Creates a new Git repository in the current directory.
git init
2. git clone
Downloads an existing remote repository to your local machine.
git clone <repo-url>
3. git status
Shows the current state of files (modified, staged, untracked).
git status
4. git add
Stages files so they’re included in the next commit.
git add .
git add file.js
5. git commit
Saves staged changes as a snapshot with a message.
git commit -m "message"
6. git push
Uploads local commits to the remote repository.
git push origin main
7. git pull
Fetches remote changes and merges them into your branch.
git pull
Branching & Navigation
8. git branch
Lists branches or creates a new branch.
git branch
git branch feature-x
9. git checkout
Switches branches or restores files.
git checkout feature-x
10. git switch
A cleaner, modern way to switch branches.
git switch main
11. git merge
Combines another branch into the current branch.
git merge feature-x
12. git log
Shows commit history for the current branch.
git log --oneline --graph
Undoing Mistakes
13. git reset
Moves HEAD and optionally discards commits or changes.
git reset --soft HEAD~1
git reset --hard HEAD~1
14. git revert
Creates a new commit that safely undoes an older commit.
git revert <commit-hash>
15. git checkout -- <file>
Discards local changes to a specific file.
git checkout -- index.js
Temporary Work
16. git stash
Temporarily saves uncommitted changes.
git stash
git stash pop
17. git stash list
Shows all saved stashes.
git stash list
Working With Remotes
18. git remote -v
Displays configured remote repositories.
git remote -v
19. git fetch
Downloads remote changes without merging them.
git fetch
Inspecting Changes
20. git diff
Shows differences between files, commits, or stages.
git diff
git diff --staged
21. git blame
Shows who last modified each line of a file.
git blame file.js
22. git show
Displays detailed information about a specific commit.
git show <commit-hash>
Cleanup & Recovery
23. git clean
Removes untracked files from the working directory.
git clean -fd
24. git reflog
Shows every move of HEAD, even deleted or lost commits.
git reflog
How Senior Engineers Actually Use Git
Senior engineers:
- check
git statusconstantly, - prefer
revertoverreseton shared branches, - use
fetchbefore risky merges, - rely on
reflogwhen things go wrong.
Git isn’t just version control—it’s your safety net.
Final Thoughts
You don’t need to memorize Git.
You need to understand enough to recover when things break.
Master these commands and you’ll:
- move faster,
- panic less,
- and collaborate better.
Git won’t make you a better engineer—but not knowing Git can absolutely make you a worse one.
Top comments (1)
thank you