Bratish Goswami

Personal website and blog

Underused Git Commands

After almost 15 years of building and shipping software, a pattern keeps repeating: most of the day goes by fine with add/commit/pull/push/merge, and then a tricky moment shows up - an urgent hotfix, a long‑running branch that needs a careful rebase, a regression hiding somewhere in the past, or a “whoops” that seems unrecoverable. When those moments come, a handful of lesser‑used commands have saved me hours and, occasionally, a release. This isn’t a victory lap—just notes from the field that I wish someone had handed me earlier.

git worktree: parallel work without extra clones

Context switching used to mean either stashing work (and praying it applies cleanly later) or recloning a big repo. At some point I switched to git worktree and never looked back. One repository, multiple working directories, each on its own branch, all sharing the same object database.

Spin up a sibling workspace for a hotfix

git worktree add -b hotfix/latency ../hotfix-latency origin/main

See what’s active

git worktree list

Clean up when done

git worktree remove ../hotfix-latency

The real gain is mental: no stash juggling, no duplicate clones, and no fear of losing WIP while jumping to something urgent. If there’s one “under‑the‑radar” feature to adopt early, it’s probably git worktree.

git rerere: resolve recurring conflicts once

Long‑lived branches and regular rebases can make the same conflict pop up again and again. Years ago, I enabled rerere, and it quietly paid rent ever since. It records how a given conflict was resolved and reuses that resolution the next time an identical conflict appears.

Turn it on (once)

git config --global rerere.enabled true

Inspect what’s being remembered

git rerere status

It won’t save every conflict—small context changes can thwart it—but it reliably auto‑applies those repetitive “rename plus nudge” merges and the inevitable package.json/version bumps. When a rebase that used to take 10 minutes suddenly takes 30 seconds, you notice.

git notes: add context without rewriting history

I like tidy commit messages, but real life doesn’t always give you the full story at commit time. Rather than amending public history, git notes lets me attach metadata after the fact—review summaries, build IDs, links to incident reports—without touching the original commit.

Add a quick note to the latest commit

git notes add -m "Load-test: 12k rps; p95=180ms; see report #427"

Make notes visible in logs

git log --show-notes

Share notes explicitly (they’re not pushed by default)

git push origin refs/notes/commits

Caveats: teammates need to fetch notes (and some hosting UIs don’t surface them), but for teams comfortable on the CLI, it’s a clean way to keep commit messages focused while still preserving the messy, useful “extra” context.

git range-diff: reviewing a rebased series

If you’ve ever force‑pushed a rebased feature branch and then tried to explain what actually changed between v1 and v2, you know that “just look at the diff” isn’t good enough. range-diff compares two commit ranges and pairs up corresponding commits, showing exactly how each one changed.

Compare a series before and after rebase

git range-diff origin/main..feature-v1 origin/main..feature-v2

This is especially helpful for code reviews on iterative patch sets. Instead of rereading the entire feature, reviewers can see which commits moved, which were dropped, and what changed inside each commit. It’s been in Git for a while now and is worth adding to the daily toolkit.

git bisect: binary search for regressions

I used to hunt regressions by intuition and grep; git bisect cured me of that habit. Point it at a known good revision and a known bad one, and it walks you through a binary search of the history until a single commit is left standing.

Minimal flow

git bisect start
git bisect bad                # current commit is broken
git bisect good v2.3.1        # a tag or SHA that definitely worked
# build & test...
git bisect good               # or: git bisect bad
# repeat until it identifies one commit
git bisect reset

If the test is scriptable

git bisect start
git bisect bad
git bisect good v2.3.1
git bisect run ./repro.sh

On large histories, the time savings are dramatic. The trick is to define a reliable “good/bad” test—after that, the process is mechanical and fast.

git reflog: the real safety net

Reflog has rescued me from more “I think I’ve lost it” moments than anything else. It tracks where HEAD and other refs have been, even when those commits are no longer reachable by normal logs. Deleted the wrong branch? Botched a rebase? Hard reset a little too hard? Reflog is usually the way back.

See recent moves

git reflog

Undo a bad rebase (jump back to before it started)

git reset --hard HEAD@{1}

Recreate a deleted branch (from a recent position)

git branch restore-me HEAD@{3}

Even stash has a reflog

git reflog show stash
git stash apply stash@{1}

One practical note: reflog is local and time‑bounded (by default). If it’s been months and garbage collection has run, truly unreachable objects may be gone. But within normal day‑to‑day windows, it’s a lifesaver.

How I use these together

On busy weeks, I’ll spin up a new workspace with git worktree for each urgent thread, keep rerere on to avoid repetitive conflicts, annotate important commits with git notes after CI finishes, and use range-diff when rebasing a patch series under review. If something breaks in a mysterious time window, bisect does the hunting. And if I make a mistake that looks catastrophic, reflog is my first stop before panic.

A short checklist

  • Enable rerere globally:
    git config --global rerere.enabled true
    
  • Learn the 3–4 worktree commands you’ll actually use.
  • Keep a simple “is this commit good?” script around for bisect.
  • Make “log with notes” part of your habit on teams that embrace notes.
  • Reach for range-diff when explaining a force‑pushed rebase.
  • When in doubt, check reflog before assuming work is lost.

None of these commands are new, and none are flashy. But they’ve repeatedly helped me ship a little more calmly and recover a little more gracefully. If one of them saves you an hour this year, it will have earned its place on your mental shelf.