Git Advanced Workflow Cheat Sheet [2026 Deep Dive]
Overview
Git power users lean on rebase, bisect, worktree, and hooks when the default add-commit-push loop is too blunt. This reference is optimized for speed: commands are grouped by purpose, terminal shortcuts are collected in one place, and the examples stay practical.
Use this when you need to clean up history before review, isolate a regression quickly, keep multiple branches checked out at once, or automate guardrails around commits and pushes.
Takeaway
Rebase keeps history readable, bisect finds breakage fast, worktrees remove branch-switching friction, and hooks turn team conventions into repeatable automation. Use all four together and Git becomes an active workflow system, not just a version store.
Live Filter
Filter the cheat sheet by command, flag, or workflow. Try queries like --onto, rerere, pre-push, or detach.
Keyboard Shortcuts
Git itself exposes few universal keybindings, so the shortcuts that matter most usually come from your shell, patch mode, and the editor used by interactive rebase.
| Shortcut | Where | Why It Matters |
|---|---|---|
| Ctrl + R | Shell | Reverse-search old git commands, hashes, and branch names. |
| Ctrl + A / Ctrl + E | Shell | Jump to start or end of a long command line before editing flags. |
| Alt + B / Alt + F | Shell | Move by word when editing complex rebase or worktree commands. |
| y, n, s, e, ? | git add -p | Accept, skip, split, manually edit, or inspect hunks during patch staging. |
| pick, reword, squash, fixup, drop | git rebase -i | These are the core moves for rewriting a branch before review. |
| !! / !$ | Shell history expansion | Reuse the last command or its last argument to speed up repetitive Git tasks. |
Commands by Purpose
History Cleanup with rebase
When to use it: before opening a pull request, before merging stacked branches, or after branch drift from main.
- git fetch origin
- git rebase origin/main
- git rebase -i HEAD~10
- git rebase --onto new-base old-base feature
- git rebase --autosquash -i origin/main
- git rebase --continue, --skip, --abort
git fetch origin
git rebase origin/main
git commit --fixup HEAD~2
git rebase --autosquash -i origin/main
git rebase --onto origin/main feature-base my-branchRule of thumb: use merge when preserving exact branch topology matters, and use rebase when readability matters more than historical fidelity.
Regression Hunting with bisect
When to use it: a bug appeared somewhere between a known good release and a broken branch tip.
- git bisect start
- git bisect bad
- git bisect good <commit>
- git bisect run <script>
- git bisect reset
git bisect start
git bisect bad
git bisect good v2.4.0
git bisect run ./scripts/test-regression.sh
git bisect resetBest pattern: automate the pass-fail check. Manual bisect works, but scripted bisect removes fatigue and ambiguity.
Parallel Branches with worktree
When to use it: reviewing one branch while another runs a hotfix, keeping release branches open, or testing against two commits without stash churn.
- git worktree list
- git worktree add ../repo-hotfix hotfix/login-loop
- git worktree add -b spike-cache ../repo-spike origin/main
- git worktree remove ../repo-hotfix
- git worktree prune
git worktree add ../app-review feature/api-cleanup
git worktree add -b release-2026-04 ../app-release origin/main
git worktree list
git worktree remove ../app-review
git worktree prunePractical gain: worktrees eliminate repeated checkout-install-build cycles when context-switching between active branches.
Local Automation with hooks
When to use it: enforce fast local checks before commit or push, especially formatting, linting, and secret scanning.
- pre-commit: format, lint, small unit checks
- commit-msg: validate conventional commits or ticket IDs
- pre-push: run slower integration checks
- post-checkout: restore generated files or dependencies if your team truly needs it
#!/bin/sh
set -eu
files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|ts|py|sh)$' || true)
[ -z "$files" ] && exit 0
npx prettier --write $files
git add $filesBefore pasting hook output or sample secrets into docs, scrub them first. The Data Masking Tool fits naturally into that workflow for security-sensitive examples.
Configuration
Good Git workflows depend on predictable defaults. Start with settings that reduce repeated conflict work, make pushes explicit, and preserve context in history inspection.
- pull.rebase=true keeps local pulls linear by default.
- rebase.autoSquash=true pairs naturally with fixup! commits.
- rerere.enabled=true records conflict resolutions and reuses them later.
- push.default=simple prevents surprise multi-branch pushes.
- fetch.prune=true removes stale remote-tracking refs.
- core.hooksPath=.githooks stores project hooks in version control.
git config --global pull.rebase true
git config --global rebase.autoSquash true
git config --global rerere.enabled true
git config --global fetch.prune true
git config --global push.default simple
git config core.hooksPath .githooksIf you share command snippets across docs, demos, and hook scripts, run them through the Code Formatter before publishing so examples stay consistent.
Advanced Usage
Stacked Branches
For branch stacks like feature-base then feature-ui, move only the child branch when the base lands.
git rebase --onto origin/main feature-base feature-uiSafer Force Pushes
After rewriting history with rebase, use --force-with-lease instead of --force so you only overwrite the remote branch if it still matches your expectation.
git push --force-with-lease origin my-branchConflict Reuse with rerere
If you repeatedly rebase long-lived topic branches, rerere can remove a surprising amount of friction by remembering identical conflict resolutions.
Temporary Review Environments with worktree
Create a throwaway review tree for a production hotfix, verify it, and delete it without disturbing your current branch or stash state.
Hook Design Rule
Keep local hooks fast, deterministic, and optional to bypass in emergencies. Put enforcement-grade checks in CI, then let hooks provide earlier feedback.
The highest-leverage Git setup in 2026 is still not exotic: interactive rebase for readable review history, bisect for bug isolation, worktrees for parallelism, and hooks for repeatability. The tools are old. The workflow discipline is what compounds.
Get Engineering Deep-Dives in Your Inbox
Weekly breakdowns of architecture, security, and developer tooling — no fluff.