The Git Commands You Actually Use (And the Ones You Pretend to Understand)
A no-nonsense guide to the 20 Git commands that cover 95% of real work. Plus honest explanations of rebase, cherry-pick, and reflog — the ones developers fake knowing.
Most Git tutorials start with init and end somewhere around branching, leaving you to figure out the actually useful parts on your own. This isn't that tutorial.
The Core Commands (Daily Use)
- git status — always run this first. Shows what's changed, what's staged, what's untracked.
- git add -p — add changes interactively, chunk by chunk. Dramatically better than git add . for crafting clean commits.
- git commit -m 'message' — commit staged changes. Write commit messages in imperative mood: 'Fix login bug' not 'Fixed login bug'.
- git log --oneline --graph -- visually shows branch history. Add --all to see all branches.
- git diff — shows unstaged changes. git diff --staged shows what's about to be committed.
Branch Management (Weekly Use)
- git checkout -b feature/name — create and switch to a new branch in one command.
- git branch -d branch-name — delete a merged branch. -D forces deletion even if unmerged.
- git merge --no-ff feature/name — merge with a merge commit, preserving branch history. --no-ff prevents fast-forward for cleaner history on significant merges.
- git push origin branch-name -- explicitly push a branch to remote. First time: git push -u origin branch-name sets the upstream.
The Powerful Ones People Avoid
git rebase -i HEAD~3 — interactive rebase. Lets you squash, reorder, reword, or drop the last 3 commits before pushing. Use this to clean up messy WIP commits into something presentable. Essential for clean pull request history.
git cherry-pick abc1234 — apply a single commit from another branch to the current one. When you've fixed a bug on a feature branch that needs to go to main without the whole feature. More precise than merging entire branches.
git reflog — your safety net. Shows every HEAD movement in the repo, including after resets and rebases. If you accidentally deleted commits, they're in reflog for 90 days. git checkout the commit SHA to recover them.
git bisect — binary search through commit history to find when a bug was introduced. git bisect start, mark good/bad commits, and Git automates the search. Finding the exact commit that introduced a regression in a codebase with 3,000 commits takes minutes instead of hours.
The Aliases Worth Setting Up
Add to ~/.gitconfig
[alias] lg = log --oneline --graph --all st = status -s co = checkout undo = reset --soft HEAD~1 aliases = config --get-regexp alias
Three Git Mistakes Most Developers Make
- Committing everything with git add . — you end up committing debug logs, temporary files, and unrelated changes. Use git add -p (patch mode) to review each change before staging.
- Force pushing to shared branches — git push --force on main or develop overwrites other people's commits. Never. If you need to force push: only on your own feature branches, and use --force-with-lease which fails if someone else pushed since your last pull.
- Unclear commit messages — 'fix stuff', 'wip', 'updates' are meaningless in a blame or log. Six months later, you'll be the one confused by your own commits. 'Fix null pointer in UserService.getProfile when email is missing' takes 10 extra seconds to write and saves 20 minutes of debugging.
Frequently Asked Questions
What's the difference between git merge and git rebase?+
How do I undo the last git commit without losing my changes?+
What is git stash and when should I use it?+
What does git fetch do vs git pull?+
🔧 Free Tools Used in This Guide
FreeToolKit Team
FreeToolKit Team
We build free browser-based tools and write practical guides without the fluff.
Tags: