Git pros use rebase, bisect, worktrees, and hooks to debug faster and automate safely. Command-first reference with config and shortcuts. Read now.
Rebase for a readable history
Rebase rewrites your branch so it sits on top of an updated base instead of merging with a noisy merge commit. Use it on local feature work before you share it: fetch the target branch, then replay your commits on top so each commit stays focused and reviewable. Interactive rebase lets you reorder, squash, reword, or drop commits so the final story matches what actually shipped.
Avoid rebasing commits others already pulled; rewriting shared history forces teammates into recovery work. Prefer merge or a carefully agreed history rewrite when branches are public. When in doubt, rebase only the commits unique to your branch, and push with care so remote history stays consistent.
Bisect to find the first bad commit
When a bug appears and you know a past revision was clean, bisect binary-searches the commit range for you. Mark a known-good and known-bad commit, then check out the midpoint, run your test or reproduce steps, and mark that revision good or bad. Each step halves the search space until Git points at the first commit that introduced the failure.
Automate the loop when you have a reliable script: bisect can run a command at each step and advance on exit code. Keep the test fast and deterministic—flaky checks waste the whole session. After you find the culprit, reset back to your original branch and fix or revert with a clear message tied to that commit.
Worktrees for parallel work without stashing chaos
A worktree is a second working directory attached to the same repository, each checked out to a different branch. Use one tree for a long-running feature, another for a hotfix, and a third for review or docs. You keep one object database and avoid constant stash, checkout, and context loss when interrupts arrive mid-task.
Name worktrees after their purpose and remove them when the branch is done so disk and mental overhead stay low. Do not check out the same branch in two trees at once; Git blocks that to protect the index and working files. Treat each tree as a full workspace: run tests, edit freely, then commit from the tree that owns that branch.
Hooks, config, and shortcuts that keep the workflow safe
Hooks run scripts at fixed points—before commit, after merge, before push—so you can enforce format, lint, or test gates without relying on memory. Keep hooks fast and local when possible; heavy shared policy belongs in CI as well, so broken machines cannot silently skip checks. Prefer client-side hooks for personal guardrails and documented shared hooks for team conventions.
- Set a stable identity, default branch, and pull behavior in your global config so every clone behaves the same way.
- Alias long multi-step commands (status, graph log, interactive rebase, worktree add/remove) to short names you actually type under pressure.
- Use conditional includes for work vs personal machines so signing keys and emails never cross contexts by accident.
Pros treat rebase, bisect, worktrees, and hooks as one toolkit: clean history when it is safe, binary-search when bugs hide in the past, parallel trees when context switches are constant, and automation that fails early. Learn the commands, then encode the ones you use daily as config and aliases so the safe path is also the fast path.