Master advanced Git workflows including rebasing
Git advanced workflows

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…
--- 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
Overview
Master advanced Git techniques to maintain clean history, collaborate effectively, and recover from any situation with confidence.
Manual install (npx, ZIP)
npx skills add wshobson/agents --skill git-advanced-workflows -g -a claude-codemkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/wshobson/agents/tar.gz/4236bb91f839 \
| tar -xz -C ~/.claude/skills --strip-components=4 agents-4236bb91f839/plugins/developer-essentials/skills/git-advanced-workflowsNew-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/17a981157ab8911bb040/git-advanced-workflows.zip" -OutFile "$env:TEMP\git-advanced-workflows.zip"; Expand-Archive "$env:TEMP\git-advanced-workflows.zip" -DestinationPath "$HOME\.claude\skills" -ForceConnects with Agent Alley MCP · agentalley.io/mcp
Files included
SKILL.md4.9 KBreferences/1 file · 3.9 KB
Read the files here
Show the full text199 lines
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
| 1 | |
| 2 | name git-advanced-workflows |
| 3 | 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. |
| 4 | |
| 5 | |
| 6 | # Git Advanced Workflows |
| 7 | |
| 8 | Master advanced Git techniques to maintain clean history, collaborate effectively, and recover from any situation with confidence. |
| 9 | |
| 10 | ## When to Use This Skill |
| 11 | |
| 12 | Cleaning up commit history before merging |
| 13 | Applying specific commits across branches |
| 14 | Finding commits that introduced bugs |
| 15 | Working on multiple features simultaneously |
| 16 | Recovering from Git mistakes or lost commits |
| 17 | Managing complex branch workflows |
| 18 | Preparing clean PRs for review |
| 19 | Synchronizing diverged branches |
| 20 | |
| 21 | ## Core Concepts |
| 22 | |
| 23 | ### 1. Interactive Rebase |
| 24 | |
| 25 | Interactive rebase is the Swiss Army knife of Git history editing. |
| 26 | |
| 27 | **Common Operations:** |
| 28 | |
| 29 | `pick`: Keep commit as-is |
| 30 | `reword`: Change commit message |
| 31 | `edit`: Amend commit content |
| 32 | `squash`: Combine with previous commit |
| 33 | `fixup`: Like squash but discard message |
| 34 | `drop`: Remove commit entirely |
| 35 | |
| 36 | **Basic Usage:** |
| 37 | |
| 38 | |
| 39 | # Rebase last 5 commits |
| 40 | git rebase -i HEAD~5 |
| 41 | |
| 42 | # Rebase all commits on current branch |
| 43 | git rebase -i $(git merge-base HEAD main) |
| 44 | |
| 45 | # Rebase onto specific commit |
| 46 | git rebase -i abc123 |
| 47 | |
| 48 | |
| 49 | ### 2. Cherry-Picking |
| 50 | |
| 51 | Apply specific commits from one branch to another without merging entire branches. |
| 52 | |
| 53 | |
| 54 | # Cherry-pick single commit |
| 55 | git cherry-pick abc123 |
| 56 | |
| 57 | # Cherry-pick range of commits (exclusive start) |
| 58 | git cherry-pick abc123..def456 |
| 59 | |
| 60 | # Cherry-pick without committing (stage changes only) |
| 61 | git cherry-pick -n abc123 |
| 62 | |
| 63 | # Cherry-pick and edit commit message |
| 64 | git cherry-pick -e abc123 |
| 65 | |
| 66 | |
| 67 | ### 3. Git Bisect |
| 68 | |
| 69 | Binary search through commit history to find the commit that introduced a bug. |
| 70 | |
| 71 | |
| 72 | # Start bisect |
| 73 | git bisect start |
| 74 | |
| 75 | # Mark current commit as bad |
| 76 | git bisect bad |
| 77 | |
| 78 | # Mark known good commit |
| 79 | git bisect good v1.0.0 |
| 80 | |
| 81 | # Git will checkout middle commit - test it |
| 82 | # Then mark as good or bad |
| 83 | git bisect good # or: git bisect bad |
| 84 | |
| 85 | # Continue until bug found |
| 86 | # When done |
| 87 | git bisect reset |
| 88 | |
| 89 | |
| 90 | **Automated Bisect:** |
| 91 | |
| 92 | |
| 93 | # Use script to test automatically |
| 94 | git bisect start HEAD v1.0.0 |
| 95 | git bisect run ./test.sh |
| 96 | |
| 97 | # test.sh should exit 0 for good, 1-127 (except 125) for bad |
| 98 | |
| 99 | |
| 100 | ### 4. Worktrees |
| 101 | |
| 102 | Work on multiple branches simultaneously without stashing or switching. |
| 103 | |
| 104 | |
| 105 | # List existing worktrees |
| 106 | git worktree list |
| 107 | |
| 108 | # Add new worktree for feature branch |
| 109 | git worktree add ../project-feature feature/new-feature |
| 110 | |
| 111 | # Add worktree and create new branch |
| 112 | git worktree add -b bugfix/urgent ../project-hotfix main |
| 113 | |
| 114 | # Remove worktree |
| 115 | git worktree remove ../project-feature |
| 116 | |
| 117 | # Prune stale worktrees |
| 118 | git worktree prune |
| 119 | |
| 120 | |
| 121 | ### 5. Reflog |
| 122 | |
| 123 | Your safety net - tracks all ref movements, even deleted commits. |
| 124 | |
| 125 | |
| 126 | # View reflog |
| 127 | git reflog |
| 128 | |
| 129 | # View reflog for specific branch |
| 130 | git reflog show feature/branch |
| 131 | |
| 132 | # Restore deleted commit |
| 133 | git reflog |
| 134 | # Find commit hash |
| 135 | git checkout abc123 |
| 136 | git branch recovered-branch |
| 137 | |
| 138 | # Restore deleted branch |
| 139 | git reflog |
| 140 | git branch deleted-branch abc123 |
| 141 | |
| 142 | |
| 143 | ## Detailed patterns and worked examples |
| 144 | |
| 145 | Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient. |
| 146 | |
| 147 | ## Best Practices |
| 148 | |
| 149 | **Always Use --force-with-lease**: Safer than --force, prevents overwriting others' work |
| 150 | **Rebase Only Local Commits**: Don't rebase commits that have been pushed and shared |
| 151 | **Descriptive Commit Messages**: Future you will thank present you |
| 152 | **Atomic Commits**: Each commit should be a single logical change |
| 153 | **Test Before Force Push**: Ensure history rewrite didn't break anything |
| 154 | **Keep Reflog Aware**: Remember reflog is your safety net for 90 days |
| 155 | **Branch Before Risky Operations**: Create backup branch before complex rebases |
| 156 | |
| 157 | |
| 158 | # Safe force push |
| 159 | git push --force-with-lease origin feature/branch |
| 160 | |
| 161 | # Create backup before risky operation |
| 162 | git branch backup-branch |
| 163 | git rebase -i main |
| 164 | # If something goes wrong |
| 165 | git reset --hard backup-branch |
| 166 | |
| 167 | |
| 168 | ## Common Pitfalls |
| 169 | |
| 170 | **Rebasing Public Branches**: Causes history conflicts for collaborators |
| 171 | **Force Pushing Without Lease**: Can overwrite teammate's work |
| 172 | **Losing Work in Rebase**: Resolve conflicts carefully, test after rebase |
| 173 | **Forgetting Worktree Cleanup**: Orphaned worktrees consume disk space |
| 174 | **Not Backing Up Before Experiment**: Always create safety branch |
| 175 | **Bisect on Dirty Working Directory**: Commit or stash before bisecting |
| 176 | |
| 177 | ## Recovery Commands |
| 178 | |
| 179 | |
| 180 | # Abort operations in progress |
| 181 | git rebase --abort |
| 182 | git merge --abort |
| 183 | git cherry-pick --abort |
| 184 | git bisect reset |
| 185 | |
| 186 | # Restore file to version from specific commit |
| 187 | git restore --source=abc123 path/to/file |
| 188 | |
| 189 | # Undo last commit but keep changes |
| 190 | git reset --soft HEAD^ |
| 191 | |
| 192 | # Undo last commit and discard changes |
| 193 | git reset --hard HEAD^ |
| 194 | |
| 195 | # Recover deleted branch (within 90 days) |
| 196 | git reflog |
| 197 | git branch recovered-branch abc123 |
| 198 | |
| 199 |
Details
- Updated
- Sep 21, 2026
- License
- MIT
- Stars on the repo
- ★ 39,857
- Checked
- Source
- wshobson/agents ↗
- Creator
- wshobson · 179 listings
Similar skills
See all →
SkillAutomates CI/CD pipeline setupCI/CD and Automation
SkillAutomated semantic versioning and release workflowVersion Bump & Release Workflow
SkillOperate Orca-managed worktrees, folder contexts, terminalsOrca CLI
SkillThreaded messages, blocking ask/reply, task dispatchOrca Orchestration
SkillDeploy applications and websites to VercelVercel deploy
SkillOpen or update a pull request on pascalorg/editorOpen PRMore from wshobson
SkillMaster C/.NET backend development patterns for building
SkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliance
SkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Design
SkillMigrate from AngularJS to Angular using hybrid modeAngular migration
SkillUnderstand anti-reversing, obfuscationAnti reversing techniques
SkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patterns