| name | gitbutler-complete-branch |
| description | This skill should be used when the user asks to "complete a branch", "merge to main", "finish my feature", "ship this branch", "integrate to main", "create a PR from GitButler", or when `--complete-branch` flag is mentioned. Guides completion of GitButler virtual branches with safety snapshots, integration workflows, and cleanup. |
| metadata | {"version":"1.0.0","author":"outfitter","category":"version-control","related-skills":["gitbutler-virtual-branches","gitbutler-stacks"]} |
Complete GitButler Virtual Branch
Virtual branch ready → snapshot → merge to main → cleanup → return.
<when_to_use>
- Virtual branch work is complete and ready to ship
- Tests pass and code is reviewed (if required)
- Ready to merge changes into main branch
- Need to clean up completed branches
NOT for: ongoing work, branches needing more development, stacks (complete bottom-to-top)
</when_to_use>
TL;DR
Using CLI (preferred): but oplog snapshot -> but push <branch> -> but pr new <branch> -> merge PR on GitHub -> but branch delete <branch>
Direct merge: but oplog snapshot -> git checkout main -> git pull -> git merge --no-ff refs/gitbutler/<branch> -> git push -> but branch delete <branch> -> git checkout gitbutler/workspace
Manual PR workflow: git push origin refs/gitbutler/<branch>:refs/heads/<branch> -> gh pr create -> merge PR -> cleanup
See detailed workflows below.
Pre-Integration Checklist
Run through before any integration:
| Check | Command | Expected |
|---|
| GitButler running | but --version | Version output |
| Work committed | but status | Committed changes, no unassigned files |
| Tests passing | bun test (or project equivalent) | All green |
| Base updated | but pull | Up to date with main |
| Snapshot created | but oplog snapshot -m "Before integrating..." | Snapshot ID returned |
Integration Workflows
A. Using CLI (Preferred)
but status
but show feature-auth
but oplog snapshot --message "Before publishing feature-auth"
but config forge auth
but push feature-auth
but pr new feature-auth
but pull
but branch delete feature-auth
Benefits:
- Full CLI workflow, no GUI needed
- Correct base branch set automatically for stacks
- Stays in GitButler workspace throughout
B. Direct Merge to Main
but status
but show feature-auth
but oplog snapshot --message "Before integrating feature-auth"
git checkout main
git pull origin main
git merge --no-ff refs/gitbutler/feature-auth -m "feat: add user authentication"
git push origin main
but branch delete feature-auth
git checkout gitbutler/workspace
C. Manual Pull Request Workflow
git push origin refs/gitbutler/feature-auth:refs/heads/feature-auth
gh pr create --base main --head feature-auth \
--title "feat: add user authentication" \
--body "Description..."
gh pr merge feature-auth --squash
git checkout main
git pull origin main
but branch delete feature-auth
git checkout gitbutler/workspace
D. Stacked Branches (Bottom-Up)
git checkout main && git pull
git merge --no-ff refs/gitbutler/feature-base -m "feat: base feature"
git push origin main
but branch delete feature-base
git checkout gitbutler/workspace
but pull
git checkout main && git pull
git merge --no-ff refs/gitbutler/feature-api -m "feat: API feature"
git push origin main
but branch delete feature-api
git checkout gitbutler/workspace
For comprehensive stacked branch management, load the gitbutler-stacks skill.
Error Recovery
Merge Conflicts
git status
git add src/auth.ts
git commit
git push origin main
but branch delete feature-auth
git checkout gitbutler/workspace
Push Rejected (Main Moved Ahead)
git pull origin main
git push origin main
Undo Integration (Not Pushed Yet)
git reset --hard HEAD~1
git checkout gitbutler/workspace
Undo Integration (Already Pushed)
git revert -m 1 HEAD
git push origin main
Post-Integration Cleanup
but branch delete feature-auth
git push origin --delete feature-auth
but status
but status
ALWAYS:
- Create snapshot before integration:
but oplog snapshot --message "..."
- Use
--no-ff flag to preserve branch history
- Return to workspace after git operations:
git checkout gitbutler/workspace
- Run tests before integrating
- Complete stacked branches bottom-to-top
NEVER:
- Merge without snapshot backup
- Skip updating main first (
git pull)
- Forget to return to
gitbutler/workspace
- Merge middle of stack before base
- Force push to main without explicit confirmation
Troubleshooting
| Symptom | Cause | Solution |
|---|
| Merge conflicts | Diverged from main | Resolve conflicts, stage, commit |
| Push rejected | Main moved ahead | git pull, resolve, push |
| Branch not found | Wrong ref path | Use refs/gitbutler/<name> |
| Can't return to workspace | Integration branch issue | git checkout gitbutler/workspace |
Emergency Recovery
but oplog
but undo
git checkout gitbutler/workspace
Best Practices
Keep branches small:
- Small branches = easier merges
- Aim for single responsibility per branch
Update base regularly:
but pull
Test before integrating:
- Always run full test suite before merging
Meaningful merge commits:
git merge --no-ff feature-auth -m "feat: add JWT-based user authentication"
git merge --no-ff feature-auth -m "Merge branch"
Related Skills
Reference Files
External