git-advanced-workflows
wshobson/agents
Master rebasing, cherry-picking, bisect, worktrees, and reflog for clean Git history and recovery.
What is git-advanced-workflows?
Advanced Git workflows for managing complex histories, collaborating on feature branches, and troubleshooting repository issues. Use when cleaning up commits, finding bugs, working on multiple features simultaneously, or recovering from Git mistakes.
- Interactive rebase to reword, squash, edit, or drop commits
- Cherry-pick specific commits across branches without full merges
- Git bisect for binary search to find bug-introducing commits
- Worktrees to work on multiple branches simultaneously without stashing
- Reflog to recover deleted commits and branches within 90 days
- Safe force-push with --force-with-lease to prevent overwriting collaborators' work
How to install git-advanced-workflows
npx skills add https://github.com/wshobson/agents --skill git-advanced-workflowsHow to use git-advanced-workflows
- 1.Review the core concepts section to understand each technique (rebase, cherry-pick, bisect, worktrees, reflog)
- 2.Create a backup branch before attempting risky operations like interactive rebase
- 3.Use interactive rebase (git rebase -i) to edit, squash, or reorder commits on your local branch
- 4.Use cherry-pick to apply specific commits to other branches when needed
- 5.Use git bisect to automatically find the commit that introduced a bug
- 6.Use worktrees (git worktree add) to work on multiple branches simultaneously
- 7.Consult reflog (git reflog) to recover deleted commits or branches
- 8.Always use --force-with-lease instead of --force when pushing rewritten history
Use cases
- Clean up commit history before submitting a pull request
- Apply a specific bugfix commit from one branch to another
- Find which commit introduced a regression using automated bisect
- Work on a hotfix while keeping your feature branch checked out
- Recover a accidentally deleted branch or lost commit
- Developers managing feature branches and pull requests
- Teams collaborating on shared repositories
- DevOps engineers troubleshooting repository history
- Anyone recovering from Git mistakes or lost work
git-advanced-workflows FAQ
Rebase for local commits before pushing to keep history clean. Use merge for shared/public branches to preserve collaboration history. Never rebase commits that have been pushed and shared with others.
Use git reflog to find your previous HEAD position, then git reset --hard <commit> to restore it. Or if you created a backup branch beforehand, git reset --hard backup-branch.
Cherry-pick applies specific commits from one branch to another. Rebase replays all commits from your branch onto a new base. Use cherry-pick for selective commits, rebase for cleaning up your entire branch history.
Provide a test script that exits 0 for good commits and 1-127 for bad ones. Git bisect run will binary search through history, running your script at each step until the bug-introducing commit is found.
Yes, use git reflog to view all ref movements, find the commit hash of the deleted branch, then run git branch <branch-name> <commit-hash>. Reflog keeps history for 90 days by default.
Full instructions (SKILL.md)
Source of truth, from wshobson/agents.
name: git-advanced-workflows description: Master advanced Git workflows including rebasing, cherry-picking, bisect, worktrees, and reflog to maintain clean history and recover from any situation. Use when managing complex Git histories, collaborating on feature branches, or troubleshooting repository issues.
Git Advanced Workflows
Master advanced Git techniques to maintain clean history, collaborate effectively, and recover from any situation with confidence.
When to Use This Skill
- Cleaning up commit history before merging
- Applying specific commits across branches
- Finding commits that introduced bugs
- Working on multiple features simultaneously
- Recovering from Git mistakes or lost commits
- Managing complex branch workflows
- Preparing clean PRs for review
- Synchronizing diverged branches
Core Concepts
1. Interactive Rebase
Interactive rebase is the Swiss Army knife of Git history editing.
Common Operations:
pick: Keep commit as-isreword: Change commit messageedit: Amend commit contentsquash: Combine with previous commitfixup: Like squash but discard messagedrop: Remove commit entirely
Basic Usage:
# Rebase last 5 commits
git rebase -i HEAD~5
# Rebase all commits on current branch
git rebase -i $(git merge-base HEAD main)
# Rebase onto specific commit
git rebase -i abc123
2. Cherry-Picking
Apply specific commits from one branch to another without merging entire branches.
# Cherry-pick single commit
git cherry-pick abc123
# Cherry-pick range of commits (exclusive start)
git cherry-pick abc123..def456
# Cherry-pick without committing (stage changes only)
git cherry-pick -n abc123
# Cherry-pick and edit commit message
git cherry-pick -e abc123
3. Git Bisect
Binary search through commit history to find the commit that introduced a bug.
# Start bisect
git bisect start
# Mark current commit as bad
git bisect bad
# Mark known good commit
git bisect good v1.0.0
# Git will checkout middle commit - test it
# Then mark as good or bad
git bisect good # or: git bisect bad
# Continue until bug found
# When done
git bisect reset
Automated Bisect:
# Use script to test automatically
git bisect start HEAD v1.0.0
git bisect run ./test.sh
# test.sh should exit 0 for good, 1-127 (except 125) for bad
4. Worktrees
Work on multiple branches simultaneously without stashing or switching.
# List existing worktrees
git worktree list
# Add new worktree for feature branch
git worktree add ../project-feature feature/new-feature
# Add worktree and create new branch
git worktree add -b bugfix/urgent ../project-hotfix main
# Remove worktree
git worktree remove ../project-feature
# Prune stale worktrees
git worktree prune
5. Reflog
Your safety net - tracks all ref movements, even deleted commits.
# View reflog
git reflog
# View reflog for specific branch
git reflog show feature/branch
# Restore deleted commit
git reflog
# Find commit hash
git checkout abc123
git branch recovered-branch
# Restore deleted branch
git reflog
git branch deleted-branch abc123
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
- Always Use --force-with-lease: Safer than --force, prevents overwriting others' work
- Rebase Only Local Commits: Don't rebase commits that have been pushed and shared
- Descriptive Commit Messages: Future you will thank present you
- Atomic Commits: Each commit should be a single logical change
- Test Before Force Push: Ensure history rewrite didn't break anything
- Keep Reflog Aware: Remember reflog is your safety net for 90 days
- Branch Before Risky Operations: Create backup branch before complex rebases
# Safe force push
git push --force-with-lease origin feature/branch
# Create backup before risky operation
git branch backup-branch
git rebase -i main
# If something goes wrong
git reset --hard backup-branch
Common Pitfalls
- Rebasing Public Branches: Causes history conflicts for collaborators
- Force Pushing Without Lease: Can overwrite teammate's work
- Losing Work in Rebase: Resolve conflicts carefully, test after rebase
- Forgetting Worktree Cleanup: Orphaned worktrees consume disk space
- Not Backing Up Before Experiment: Always create safety branch
- Bisect on Dirty Working Directory: Commit or stash before bisecting
Recovery Commands
# Abort operations in progress
git rebase --abort
git merge --abort
git cherry-pick --abort
git bisect reset
# Restore file to version from specific commit
git restore --source=abc123 path/to/file
# Undo last commit but keep changes
git reset --soft HEAD^
# Undo last commit and discard changes
git reset --hard HEAD^
# Recover deleted branch (within 90 days)
git reflog
git branch recovered-branch abc123
Related skills
More from wshobson/agents and the wider catalog.
tailwind-design-system
Build production-ready design systems with Tailwind CSS v4, design tokens, and component libraries.
typescript-advanced-types
Master TypeScript's advanced type system: generics, conditional types, mapped types, and utility types for type-safe applications.
nodejs-backend-patterns
Build production-ready Node.js backends with Express/Fastify, middleware patterns, auth, and database integration.
python-performance-optimization
Profile and optimize Python code using cProfile, memory profilers, and performance best practices.
brand-landingpage
Brand-first landing page designer with guided interviews and Stitch-powered iteration.
python-testing-patterns
Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development.