| name | branch-integration-workflow |
| description | Safely review and merge remote branches into stable. Trigger when: (1) reviewing open PRs, (2) integrating feature branches, (3) checking for stale branches with potential conflicts. |
| author | Claude Code |
| date | "2024-12-31T00:00:00.000Z" |
Branch Integration Workflow
Experiment Overview
| Item | Details |
|---|
| Date | 2024-12-31 |
| Goal | Safely review and integrate remote branches when gh CLI unavailable |
| Environment | Git repository with multiple remote feature branches |
| Status | Success |
Context
Problem: Need to review and merge remote branches, but gh CLI may not be available. Must safely identify which branches can merge cleanly and which have conflicts.
Solution: Use git commands to analyze branches, test merges non-destructively, and integrate cleanly.
Verified Workflow
1. Fetch All Remote Branches
git fetch --all
git branch -r
Example output:
origin/claude/python-3.14-upgrade-analysis-fmdvv
origin/claude/update-training-v2.7.0-Zl9eH
origin/feature/v3.0-multi-agent
origin/release/v2.3.0
origin/stable
2. Analyze Branch Status
Check how far behind/ahead each branch is relative to stable:
for branch in origin/claude/python-3.14-upgrade-analysis-fmdvv origin/feature/v3.0-multi-agent; do
echo "=== $branch ==="
git log $branch --oneline -3
echo "Behind stable by:"
git rev-list --count $branch..stable
echo ""
done
3. Build Analysis Table
| Branch | Behind Stable | Content Summary | Recommendation |
|---|
claude/python-3.14-* | 4 commits | Docs, CI updates | Merge |
claude/update-training-* | 4 commits | Tests, notebook | Merge |
feature/v3.0-* | 14 commits | Major feature | Review conflicts |
release/v2.3.0 | 105 commits | Old release | Delete |
4. Test Merge Non-Destructively
CRITICAL: Always test merge before actually merging.
git stash
git checkout -b test-merge-branch stable
git merge --no-commit --no-ff origin/branch-name
Possible outcomes:
- "Automatic merge went well" → Safe to merge
- "CONFLICT" → Needs manual resolution
git diff --cached --stat
git merge --abort
git checkout stable
git branch -D test-merge-branch
git stash pop
5. Merge Clean Branches
Once confirmed clean:
git merge origin/branch-name --no-edit
git merge origin/branch-name -m "Merge branch-name: description"
6. Run Tests After Merge
python -m pytest tests/ -v --tb=short
7. Handle Branches with Conflicts
For branches that don't merge cleanly:
git checkout -b resolve-conflicts stable
git merge --no-commit origin/conflicting-branch
git status | grep "both modified"
Options:
- Defer: Complex conflicts may need dedicated session
- Resolve: Simple conflicts can be fixed manually
- Rebase: Branch author should rebase onto stable first
8. Delete Obsolete Branches
For branches significantly behind with no unique value:
git branch -D old-branch
git push origin --delete old-branch
Decision Matrix
| Commits Behind | Merges Cleanly | Action |
|---|
| < 10 | Yes | Merge immediately |
| < 10 | No | Review conflicts, resolve if simple |
| 10-50 | Yes | Merge, verify tests carefully |
| 10-50 | No | Defer - significant conflict resolution needed |
| > 50 | Any | Likely obsolete - consider deleting |
Failed Attempts
| Attempt | Why it Failed | Lesson Learned |
|---|
| Merge without testing first | Conflicts discovered mid-merge, messy abort | Always test with --no-commit first |
| Merge multiple branches at once | Hard to identify which caused test failures | Merge one at a time, test between |
| Assume clean merge = safe | Tests can still fail after clean merge | Always run tests after merge |
| Force push to fix bad merge | Rewrites history, breaks collaborators | Never force push to shared branches |
| Skip stashing local changes | Test merge fails due to dirty working tree | Always start with clean working directory |
Commands Reference
git branch -r
git rev-list --count stable..origin/branch
git rev-list --count origin/branch..stable
git merge-base stable origin/branch
git log origin/branch --oneline -10
git merge --no-commit --no-ff origin/branch
git diff --cached --stat
git merge --abort
git merge origin/branch --no-edit
git push origin --delete branch-name
Checklist
Key Insights
- Test before merge:
--no-commit --no-ff is non-destructive
- One at a time: Merge branches individually to isolate issues
- Tests are truth: Clean merge doesn't guarantee working code
- Old branches decay: >50 commits behind usually means obsolete
- Clean working tree: Stash changes before testing merges
References