Tooling6 min read

Git Advanced Workflows

Master Git workflows: interactive rebase, bisect, worktrees, reflog recovery, hooks, and branch strategies for teams.

gitversion-controlcollaborationdevops

Git mastery separates engineers who fight their version control from those who use it as a thinking tool. Advanced Git workflows - clean history, fast debugging, and automated enforcement - make code archaeology possible and catch issues before they ship.

Keep commits small, atomic, and meaningful. Use interactive rebase to clean up before merging. Use bisect to find bugs in O(log n) time. Automate code quality with pre-commit hooks. Prefer trunk-based development with feature flags over long-lived branches.

Workflow

  1. Write meaningful commits with atomic changesCommit history is documentation; "fix stuff" commits are documentation debt.
  2. Rewrite history with interactive rebaseClean history on main makes code review, bisect, and reverting precise.
  3. Debug with git bisectFinding when a bug was introduced manually takes hours; bisect does it in O(log n) commits.
  4. Recover lost work with refloggit reflog records every HEAD change - nothing is truly lost until it's garbage collected (~30 days).
  5. Automate with hooks and worktreesHooks enforce standards at the git layer; worktrees let you check out multiple branches simultaneously.

Output Format

Conventional commit messages, interactive rebase before PRs, bisect used for bug hunting, hooks enforcing quality gates, worktrees for parallel work.

Examples

Bisect automation: `git bisect start && git bisect bad && git bisect good v2.0.0 && git bisect run npm test -- --grep "checkout should work"`
Husky pre-commit: `"pre-commit": "lint-staged"` in package.json; `.lintstagedrc: { "*.{ts,tsx}": ["eslint --fix", "prettier --write"] }`
Fixup workflow: `git commit --fixup=HEAD~2` then `git rebase -i --autosquash HEAD~5` - automatically squashes the fixup into its target commit

Edge Cases & Gotchas

  • Rebase vs merge debate: use rebase for personal branches pre-PR (clean history); use merge commits for feature branches on main (preserve context of when changes landed)
  • Large binary files: use Git LFS (Large File Storage); regular git bloats the repo permanently - objects can't be removed without history rewrite
  • Shallow clones in CI: `git clone --depth=1` breaks bisect; ensure CI clones have enough depth or use full clone for bisect automation

When to Break These Rules

  • During active debugging sessions, disable pre-commit hooks temporarily: `git commit --no-verify`. Re-enable immediately after - hooks failing should be fixed, not bypassed habitually.

Reference Files

  • Pro Git book (free): https://git-scm.com/book
  • Conventional Commits: https://www.conventionalcommits.org/
  • Husky: https://typicode.github.io/husky/
  • Git worktrees: https://git-scm.com/docs/git-worktree

More skills in this library

Browse all technical skills - Mobile, AI/ML, Web, Backend, Design, and Product.