DEV Community

Cover image for 10 Git Commands That 90% of Developers Don't Know Exist
MaxxMini
MaxxMini

Posted on • Edited on

10 Git Commands That 90% of Developers Don't Know Exist

You use git add, commit, push every day. But Git has hidden power tools that can save hours of debugging, undo catastrophic mistakes, and make your workflow 10× faster.

Here are 10 commands most developers never learn — but should.


1. git rebase -i HEAD~5 — Interactive Rebase

Squash messy commits, reorder history, or edit commit messages before pushing.

git rebase -i HEAD~5
# Opens editor with last 5 commits
# Change "pick" to "squash", "reword", "edit", or "drop"
Enter fullscreen mode Exit fullscreen mode

💡 Pro tip: Use fixup instead of squash to auto-discard the commit message.


2. git stash -p — Partial Stash

Stash only specific hunks, not everything. Perfect when you're mid-feature but need a quick fix.

git stash -p
# Git asks hunk by hunk: "Stash this hunk? [y,n,q,a,d,/,s,e,?]"
Enter fullscreen mode Exit fullscreen mode

💡 Pro tip: Press s to split a large hunk into smaller pieces.


3. git bisect — Binary Search for Bugs

Find the exact commit that introduced a bug in O(log n) steps.

git bisect start
git bisect bad              # Current commit is broken
git bisect good v1.0.0      # This tag was working
# Git checks out middle commit — test it, then:
git bisect good  # or  git bisect bad
# Repeat until Git finds the culprit
Enter fullscreen mode Exit fullscreen mode

💡 Pro tip: Automate with git bisect run npm test — Git runs your test suite on each step.


4. git reflog — Undo Anything

Accidentally deleted a branch? Force-pushed over your work? Reflog remembers everything.

git reflog
# Shows every HEAD movement with SHA
git checkout -b recovered abc1234
# Restore any "lost" commit
Enter fullscreen mode Exit fullscreen mode

💡 Pro tip: git reflog expire --expire=90.days.ago — entries last 90 days by default. You have time.


5. git cherry-pick — Grab Specific Commits

Pull one commit from another branch without merging everything.

git cherry-pick abc1234
# Applies that commit to current branch

git cherry-pick abc1234..def5678
# Pick a range of commits
Enter fullscreen mode Exit fullscreen mode

💡 Pro tip: Use -n (no-commit) to stage changes without committing — useful for combining multiple picks.


6. git worktree — Multiple Branches at Once

Work on two branches simultaneously without stashing or switching.

git worktree add ../hotfix-branch hotfix/urgent
# Creates a new working directory linked to the same repo
cd ../hotfix-branch
# Fix the bug here while your feature branch stays untouched
Enter fullscreen mode Exit fullscreen mode

💡 Pro tip: Each worktree shares the same .git — no extra clone, no extra disk space for objects.


7. git blame -L 10,20 file.js — Line-Range History

See who changed specific lines and when. Way more useful than blaming the whole file.

git blame -L 10,20 src/utils.js
# Shows author + commit for lines 10-20 only

git blame -L '/function calculate/,+10' src/utils.js
# Blame by regex pattern
Enter fullscreen mode Exit fullscreen mode

💡 Pro tip: Add -w to ignore whitespace changes — skip the "reformatting" commits.


8. git log --oneline --graph --all — Visual Branch Map

See your entire branch history as an ASCII tree.

git log --oneline --graph --all --decorate
# * abc1234 (HEAD -> main) Merge feature-x
# |\
# | * def5678 Add new feature
# |/
# * 789abcd Previous release
Enter fullscreen mode Exit fullscreen mode

💡 Pro tip: Create an alias: git config --global alias.lg "log --oneline --graph --all --decorate"


9. git diff --stat — Change Summary

Get a bird's-eye view of what changed without scrolling through diffs.

git diff --stat main..feature
#  src/api.js    | 45 ++++++++++-----
#  src/utils.js  |  8 ++--
#  tests/api.test.js | 32 ++++++++++++
#  3 files changed, 62 insertions(+), 23 deletions(-)
Enter fullscreen mode Exit fullscreen mode

💡 Pro tip: Combine with --shortstat for just the summary line. Perfect for PR descriptions.


10. git shortlog -sn — Contributor Leaderboard

See who contributed most commits. Great for open-source insights.

git shortlog -sn --no-merges
#    142  Alice
#     87  Bob
#     45  Charlie

git shortlog -sn --since="2024-01-01"
# Filter by date range
Enter fullscreen mode Exit fullscreen mode

💡 Pro tip: Add --email to group by email instead of name (catches duplicate accounts).


Want the Complete Reference?

These 10 commands are just the surface. The full Git & GitHub Cheat Sheet covers:

  • Advanced rebasing patterns (split commits, rebase onto)
  • GitHub-specific shortcuts (gh CLI, code review workflows)
  • Git hooks for automated linting, testing, commit formatting
  • Conflict resolution strategies with visual examples
  • Submodules & subtrees explained simply
  • CI/CD integration patterns

More by MaxMini

🛠️ 27+ Free Developer Tools — JSON formatter, UUID generator, password analyzer, and more. All browser-based, no signup.

🎮 27 Browser Games — Built with vanilla JS. Play instantly, no install.

📚 Developer Resources on Gumroad — AI prompt packs, automation playbooks, and productivity guides.

💰 DonFlow — Free budget tracker. Plan vs reality, zero backend.


More Cheat Sheets for Developers

Topic What's Inside Link

📊 Track your finances visually — no signup, no server, 100% browser-based → Try DonFlow free

Top comments (0)