docs/research/research_git_branch_integration_2025.md
Research Date: 2025-10-16 Query: Git merge strategies for integrating divergent master/dev branches with both having valuable changes Confidence Level: High (based on official Git docs + 2024-2025 best practices)
When master and dev branches have diverged with independent commits on both sides, merge is the recommended strategy to integrate all changes from both branches. This preserves complete history and creates a permanent record of integration decisions.
# Step 1: Update dev with master's changes
git checkout dev
git merge master # Brings upstream updates into dev
# Step 2: When ready for release
git checkout master
git merge dev # Integrates PM Agent work into master
Source: Atlassian Git Tutorial, nvie.com Git branching model
Key Principles:
develop (or dev) = active development branchmaster (or main) = production-ready releasesRelease Process:
devdev is stable and feature-complete → merge to masterdevSource: Git official docs, Git Tower, Julia Evans blog (2024)
When branches have diverged (both have unique commits), three options exist:
| Strategy | Command | Result | Best For |
|---|---|---|---|
| Merge | git merge | Creates merge commit, preserves all history | Keeping both sets of changes (RECOMMENDED) |
| Rebase | git rebase | Replays commits linearly, rewrites history | Clean linear history (NOT for published branches) |
| Fast-forward | git merge --ff-only | Only succeeds if no divergence | Fails in this case |
Why Merge is Recommended Here:
Source: Git official documentation, git-scm.com Advanced Merging
How Git Merges:
Conflict Resolution:
<<<<<<<, =======, >>>>>>>git add + git commit completes the mergeConflict Resolution Options:
# Accept all changes from one side (use cautiously)
git merge -Xours master # Prefer current branch changes
git merge -Xtheirs master # Prefer incoming changes
# Manual resolution (recommended)
# 1. Edit files to resolve conflicts
# 2. git add <resolved-files>
# 3. git commit (creates merge commit)
Source: DataCamp, Atlassian, Stack Overflow discussions
| Aspect | Merge | Rebase |
|---|---|---|
| History | Preserves exact history, shows true timeline | Linear history, rewrites commit timeline |
| Conflicts | Resolve once in single merge commit | May resolve same conflict multiple times |
| Safety | Safe for published/shared branches | Dangerous for shared branches (force push required) |
| Traceability | Merge commit shows integration point | Integration point not explicitly marked |
| CI/CD | Tests exact production commits | May test commits that never actually existed |
| Team collaboration | Works well with multiple contributors | Can cause confusion if not coordinated |
2024 Consensus:
Source: Various development tool documentation
Tools that make merge easier:
CI/CD Considerations:
Option A: Standard GitFlow (Recommended)
# Bring master's updates into dev first
git checkout dev
git merge master -m "Merge master upstream updates into dev"
# Resolve any conflicts if they occur
# Continue development on dev
# Later, when ready for release
git checkout master
git merge dev -m "Release: Integrate PM Agent refactoring"
git tag -a v1.x.x -m "Release version 1.x.x"
Option B: Immediate Integration (if PM Agent work is ready)
# If dev's PM Agent work is production-ready now
git checkout master
git merge dev -m "Integrate PM Agent refactoring from dev"
# Resolve any conflicts
# Then sync dev with updated master
git checkout dev
git merge master
# When conflicts occur during merge
git status # Shows conflicted files
# Edit each conflicted file:
# - Locate conflict markers (<<<<<<<, =======, >>>>>>>)
# - Keep the correct code (or combine both approaches)
# - Remove conflict markers
# - Save file
git add <resolved-file> # Stage resolution
git merge --continue # Complete the merge
# Check that both sets of changes are present
git log --graph --oneline --decorate --all
git diff HEAD~1 # Review what was integrated
# Verify functionality
make test # Run test suite
make build # Ensure build succeeds
❌ Don't: Use rebase on shared branches (dev, master) ✅ Do: Use merge to preserve collaboration history
❌ Don't: Force push to master/dev after rebase ✅ Do: Use standard merge commits that don't require force pushing
❌ Don't: Choose one branch and discard the other ✅ Do: Integrate both branches to keep all valuable work
❌ Don't: Resolve conflicts blindly with -Xours or -Xtheirs
✅ Do: Manually review each conflict for optimal resolution
❌ Don't: Forget to test after merging ✅ Do: Run full test suite after every merge
For the current situation where both dev and master have valuable commits:
This approach preserves all work from both branches and follows 2024-2025 industry best practices.
Confidence: HIGH - Based on official Git documentation and consistent recommendations across multiple authoritative sources from 2024-2025.