Skip to content
15 Actually Useful Git Commands You Probably Don't Know

15 Actually Useful Git Commands You Probably Don't Know

DodaTech Updated Jun 20, 2026 4 min read

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 --decorate --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.

What is the difference between git revert and git reset?
git revert creates a new commit that undoes changes — safe for shared branches. git reset moves HEAD backward and can discard commits — only use on branches you haven’t pushed. Never git reset --hard on a shared branch.
When should I use git worktree instead of git stash?
Use git worktree when you need to work on two branches simultaneously — switching back and forth. Use git stash when you need to temporarily set aside changes to switch branches briefly. Worktrees are isolated directories, stashes are temporary.
Does git bisect work with any test framework?
Yes — git bisect run accepts any command that exits 0 (good) or non-zero (bad). Hook up your test framework, a build script, or even a manual check via a wrapper script.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro