· Tools · 3 min read
Git Commands Every Developer Should Know
A practical walkthrough of the Git commands you'll actually reach for day to day — from everyday status checks to branching, stashing, and undoing mistakes.
Git has a huge surface area, but most of the day-to-day work happens with a small, repeatable set of commands. Here’s a practical tour of the ones worth actually knowing well — grouped by what you’re trying to get done, not by how Git’s docs happen to organize them.
The Daily Loop
These are the commands you’ll type dozens of times a day.
git status
git add <file>
git commit -m "message"
git push
git pullgit status— always start here. It tells you what’s staged, what’s changed, and what’s untracked.git add <file>— stage specific files. Prefer this overgit add .so you know exactly what’s going into the commit.git commit -m "message"— commit staged changes with a clear, descriptive message.git push/git pull— sync your local branch with the remote.
Branching
git branch
git checkout -b feature/my-change
git switch main
git branch -d feature/my-changegit branch— list local branches.git checkout -b <name>(orgit switch -c <name>) — create and switch to a new branch in one step.git switch <name>— move between existing branches without touching your working files.git branch -d <name>— delete a branch once it’s merged (use-Dto force-delete an unmerged one, carefully).
Inspecting History
git log --oneline --graph
git diff
git diff --staged
git blame <file>git log --oneline --graph— a compact, readable view of commit history and branch structure.git diff— see unstaged changes.git diff --staged— see exactly what’s about to be committed.git blame <file>— find out which commit last touched a given line.
Undoing Things
This is the category that saves the most time once you know it.
git restore <file>
git restore --staged <file>
git reset --soft HEAD~1
git revert <commit>git restore <file>— discard unstaged changes to a file.git restore --staged <file>— unstage a file without losing the changes.git reset --soft HEAD~1— undo the last commit but keep the changes staged, ready to re-commit.git revert <commit>— the safe way to undo a commit that’s already been pushed; it adds a new commit instead of rewriting history.
Avoid
git reset --hardandgit push --forceunless you’re certain — both can discard work that’s hard to recover.
Stashing
Handy when you need to switch context without committing half-finished work.
git stash
git stash list
git stash popgit stash— shelve your uncommitted changes and return to a clean working tree.git stash list— see everything you’ve stashed.git stash pop— reapply the most recent stash and remove it from the stash list.
Keeping a Clean History
git rebase main
git commit --amend
git cherry-pick <commit>git rebase main— replay your branch’s commits on top of the latestmain, keeping history linear.git commit --amend— fix the most recent commit’s message or contents before pushing.git cherry-pick <commit>— apply a specific commit from another branch onto your current one.
A Few Habits Worth Building
- Run
git statusbefore and after almost everything — it costs nothing and prevents surprises. - Write commit messages that explain why, not just what — the diff already shows what changed.
- Prefer
git revertovergit reseton anything already pushed or shared with others. - Keep branches short-lived; the longer a branch diverges from
main, the more painful the eventual merge.
None of this requires memorizing Git’s entire command set. A handful of these, used consistently, covers the vast majority of real work.