Most developers use a small subset of Git: clone, add, commit, push, pull, merge, and occasionally rebase. The advanced Git commands that solve real problems in production workflows are less commonly known. Here are the ones worth learning.
git bisect: Binary Search for Bugs
When you know a bug exists in the current codebase but didn’t exist three months ago, bisect lets you binary-search through the commit history to find the exact commit that introduced it. Usage: `git bisect start`, `git bisect bad` (current commit is broken), `git bisect good [commit-hash]` (a known good state). Git checks out the midpoint commit; you test whether the bug is present; `git bisect good` or `git bisect bad`; Git moves to the next midpoint. After N checks (log₂ of commits between good and bad), bisect identifies the exact breaking commit. If you have an automated test that detects the bug, `git bisect run ./test.sh` automates the entire process — Git runs the script at each midpoint and determines good/bad automatically. For a 1,000-commit range: 10 manual checks, or fully automated with a test script. Invaluable for regression debugging in large codebases.
git reflog: The Safety Net
The reflog records every movement of HEAD, including after `git reset –hard`, `git rebase`, or accidental branch deletion. If you accidentally lose commits, `git reflog` shows the history of HEAD positions and lets you recover. Usage: `git reflog` shows entries like `abc1234 HEAD@{2}: reset: moving to HEAD~2`. To recover: `git reset –hard HEAD@{2}` or `git checkout -b recovery-branch HEAD@{2}`. Reflog entries expire after 90 days by default. The practical advice: before running any destructive Git operation, note the current HEAD hash (`git log –oneline -1`). If something goes wrong, the reflog will show you the path back.
git worktree: Multiple Working Copies
Git worktree creates additional working copies of the repository linked to the same Git object store. Use case: you’re in the middle of a complex feature branch and need to urgently check out main to fix a bug — without stashing, switching branches, and losing your mental state. With worktree: `git worktree add ../project-hotfix main` creates a second working directory at `../project-hotfix` pointing to main, while your original directory stays on the feature branch. Both are live simultaneously. Clean up: `git worktree remove ../project-hotfix`. Modern CI systems use worktrees for parallel test runs on the same machine without full repository clones.
git log Useful Patterns
`git log –oneline –graph –all –decorate`: the most useful git log invocation — shows a compact, ASCII-art branch graph of all branches. Worth aliasing. `git log -S “function_name”`: pickaxe search — finds all commits that added or removed a specific string. Use when you want to know when a specific function was introduced or removed. `git log –follow -p — path/to/file`: shows all changes to a file across its entire history, including renames. `git log main..feature-branch`: shows commits in feature-branch that are not in main. `git log –author=”name” –since=”2 weeks ago”`: filter by author and time range. `git show commit-hash:path/to/file`: show the content of a file as it was at a specific commit — without checking out the commit. Useful for pulling a specific version of a file without switching branches.
git stash Advanced Usage
`git stash push -m “descriptive message” — specific/file`: stash only specific files (not everything), with a descriptive label. `git stash list`: see all stash entries with their messages. `git stash show -p stash@{0}`: see the diff in a specific stash. `git stash branch new-branch-name stash@{0}`: create a new branch from a stash entry — useful when you realise mid-stash that you should have been on a new branch. `git stash drop stash@{0}`: remove a specific stash without applying it.




