Resolving Git Merge Conflicts in a Multi-Branch Workflow
The Problem
I encountered a situation where multiple pull requests (PRs) in a React project had become unmergeable due to conflicts. The project had progressed through several weekly iterations, each building upon the previous work:
- Week 1: Initial setup
- Week 2: Component structure
- Week 3: State management
- Week 4: Complete functionality with hooks
Diagnosing the Issue
To identify the merge conflict status, I used these GitHub CLI commands:
# List all PRs with their status
gh pr list --state all --limit 10
# Check detailed merge status for each PR
gh pr view 2 --json state,mergeable,mergeStateStatus
gh pr view 3 --json state,mergeable,mergeStateStatus
gh pr view 4 --json state,mergeable,mergeStateStatus
The output revealed:
- PR #2 and #3:
"mergeable":"CONFLICTING"
- PR #4:
"mergeable":"MERGEABLE"
Understanding the Root Cause
The conflicts occurred because:
- Each week's branch was created from the previous week's branch
- Later PRs included all changes from earlier weeks
- Attempting to merge older PRs after newer ones created conflicts
The Solution
Instead of resolving conflicts in older PRs, I took a more efficient approach:
# 1. Merge the most recent PR that includes all changes
gh pr merge 4 --merge
# 2. Verify the merge was successful
gh pr view 4 --json state
# 3. Update local main branch
git checkout main
git pull origin main
Key Takeaways
- Check PR dependencies: Before merging, verify if newer PRs already include changes from older ones
- Use CLI tools: The GitHub CLI provides detailed merge status information not visible in the UI
- Consider PR order: When working with sequential branches, merge in chronological order or skip redundant PRs
- Keep branches updated: Regularly rebase feature branches on main to prevent conflicts
Useful Commands Reference
# Check all branches (local and remote)
git branch -a
# View PR merge conflicts
gh pr view <number> --json mergeable,mergeStateStatus
# Rebase current branch on main
git rebase main
# Create and switch to new branch
git checkout -b branch-name
This approach saved time by avoiding unnecessary conflict resolution and ensured a clean commit history.
If you enjoyed this article, you can also find it published on LinkedIn and Medium.