15 Actually Useful Git Commands You Probably Don't Know
In this tutorial, you'll learn about 15 actually useful git commands you probably don't know. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
Commit, push, pull, merge — those get you through the day. But Git has a deeper set of commands that solve specific problems: finding where a bug was introduced, working on multiple branches without stashing, recovering commits you thought were gone forever, and making sense of a tangled history. These are the commands that separate "I use Git" from "I know Git."
Debugging & Recovery
git bisect — Binary search through commit history to find the exact commit that introduced a bug. Marks commits as "good" or "bad" and Git narrows down the culprit. Automatable with git bisect run and a test script.
git bisect start
git bisect bad HEAD
git bisect good v2.0.0
# Git checks out the midpoint — test it, then:
git bisect good # or git bisect bad
# Repeat ~log2(n) times until the guilty commit is found
git reflog — Records every movement of HEAD — commits, resets, rebases, cherry-picks. When you lose work, reflog is the safety net. git reflog shows the history, git reset --hard HEAD@{2} jumps back.
git reflog
# Outputs everything HEAD has pointed to, with reasons
git blame — Shows who last modified each line of a file and in which commit. Indispensable for understanding why a change was made.
git blame config.py
# Shows commit hash, author, date, and line content per line
History & Visualization
git log --graph — Renders the commit tree as ASCII art. Combined with --oneline --<a href="/design-patterns/decorator/">Decorate</a> --all, gives you the clearest picture of branch structure.
git log --graph --oneline --decorate --all
git diff --word-diff — Shows diffs at the word level instead of line level. When you change a single word in a paragraph, line-level diff shows the whole line as changed. Word diff shows exactly what changed.
git diff --word-diff
git shortlog — Aggregates commits by author. Useful for generating changelogs and release notes.
git shortlog -sn # Summary with commit counts per author
Rebasing & Cherry-Picking
git rebase --interactive — Rewrites commit history with squash, reword, reorder, and drop operations. The clean history toolbox. git rebase -i HEAD~5 lets you edit the last 5 commits.
git rebase -i HEAD~5
# Editor opens with pick/squash/reword/drop options per commit
git cherry-pick — Applies a specific commit from any branch onto the current branch. No merge, no rebase — just bring in that one commit.
git cherry-pick a1b2c3d
Worktrees & Sparse Checkout
git worktree — Checks out multiple branches simultaneously in separate directories. No stashing, no cloning again. Each worktree is a full working directory pointing to a different branch.
git worktree add ../project-feature feature-branch
# Now ../project-feature has feature-branch checked out
git sparse-checkout — Checks out only a subset of files from a Repository. Essential for monorepos where you only need one service's code.
git sparse-checkout set services/api/
Cleanup & Archive
git revert — Creates a new commit that undoes a previous commit. Safe for shared branches because it doesn't rewrite history.
git revert HEAD # Creates a commit that undoes the last commit
git reset --soft vs --hard — --soft moves HEAD but keeps changes staged. --hard discards everything. --mixed (default) unstages but keeps file changes.
git reset --soft HEAD~1 # Undo commit, keep changes staged
git reset --hard HEAD~1 # Undo commit, discard changes entirely
git stash push -m "description" — Stashes with a message. git stash list then shows meaningful descriptions. git stash pop applies and removes, git stash drop discards.
git stash push -m "WIP: refactoring auth module"
git stash list # Shows: stash@{0}: On main: WIP: refactoring auth module
git stash pop # Applies and removes the stash
git archive — Creates a tar or zip of the Repository at a specific commit. Cleaner than copying files — ignores untracked and git-tracked artifacts.
git archive --format=zip HEAD > project.zip
git submodule — Embeds one Repository inside another at a pinned commit. Useful for shared libraries, though git subtree is often a better choice.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro