Conflict Resolution Workshop
Simulate conflicting branches, resolve conflicts, and complete the PR workflow.
Setup
Create a repository with a base file:
bash1$ mkdir conflict-practice && cd conflict-practice2$ git init34$ cat > home.md << 'EOF'5# Welcome67This is the home page.89## Features1011- Feature A12- Feature B13EOF1415$ git add home.md16$ git commit -m "initial home page"
Part 1: Create Conflicting Branches
Branch A: Update Copy
bash1$ git checkout -b feature/branch-a23$ cat > home.md << 'EOF'4# Welcome to Our Site56This is the **new and improved** home page.78## Features910- Feature A11- Feature B12- Feature C (from Branch A)13EOF1415$ git add home.md16$ git commit -m "feat: update copy (Branch A)"
Branch B: Different Changes
bash1$ git checkout main2$ git checkout -b feature/branch-b34$ cat > home.md << 'EOF'5# Welcome67This is the home page with metrics.89## Features1011- Feature A12- Feature B1314## Metrics1516- 1000 users17- 99% uptime18EOF1920$ git add home.md21$ git commit -m "feat: add metrics (Branch B)"
Part 2: Merge Branch A First
bash1$ git checkout main2$ git merge feature/branch-a3Updating abc123..def4564Fast-forward5 home.md | 6 +++---6 1 file changed, 3 insertions(+), 3 deletions(-)78$ git log --oneline -29def456 feat: update copy (Branch A)10abc123 initial home page
Branch A merged cleanly (fast-forward).
Part 3: Hit a Conflict
Now try to merge Branch B:
bash1$ git merge feature/branch-b2Auto-merging home.md3CONFLICT (content): Merge conflict in home.md4Automatic merge failed; fix conflicts and then commit the result.
Examine the Conflict
bash1$ git status2On branch main3You have unmerged paths.45Unmerged paths:6 both modified: home.md78$ cat home.md9<<<<<<< HEAD10# Welcome to Our Site1112This is the **new and improved** home page.1314## Features1516- Feature A17- Feature B18- Feature C (from Branch A)19=======20# Welcome2122This is the home page with metrics.2324## Features2526- Feature A27- Feature B2829## Metrics3031- 1000 users32- 99% uptime33>>>>>>> feature/branch-b
Resolve the Conflict
Edit home.md to combine both changes:
bash1$ cat > home.md << 'EOF'2# Welcome to Our Site34This is the **new and improved** home page with metrics.56## Features78- Feature A9- Feature B10- Feature C (from Branch A)1112## Metrics1314- 1000 users15- 99% uptime16EOF
Complete the Merge
bash1$ git add home.md2$ git commit -m "merge: combine Branch A and B updates"34$ git log --oneline -35ghi789 merge: combine Branch A and B updates6def456 feat: update copy (Branch A)7abc123 initial home page
Part 4: Conflict During Rebase
Let's simulate a rebase conflict:
bash1# Create a new branch from an older commit2$ git checkout -b feature/rebase-test main~234$ echo "Rebase test content" >> home.md5$ git add home.md6$ git commit -m "feat: rebase test change"78# Try to rebase onto current main9$ git rebase main10Auto-merging home.md11CONFLICT (content): Merge conflict in home.md12error: could not apply xyz... feat: rebase test change
Resolve Rebase Conflict
bash1$ git status2Unmerged paths:3 both modified: home.md45# Edit the file to resolve6$ vim home.md7# Remove markers, keep desired content89# Stage and continue10$ git add home.md11$ git rebase --continue
Force Push After Rebase
If this branch was already pushed:
bash1$ git push --force-with-lease origin feature/rebase-test
Part 5: Using Merge Tools
Configure VS Code as Merge Tool
bash1$ git config merge.tool vscode2$ git config mergetool.vscode.cmd 'code --wait $MERGED'
Create Another Conflict
bash1$ git checkout main2$ git checkout -b feature/tool-test34$ echo "Tool test A" >> home.md5$ git add home.md6$ git commit -m "tool test A"78$ git checkout main9$ echo "Tool test B" >> home.md10$ git add home.md11$ git commit -m "tool test B"1213$ git checkout feature/tool-test14$ git rebase main15CONFLICT...
Use Merge Tool
bash1$ git mergetool
VS Code opens with a three-way merge interface.
After resolving:
bash1$ git add home.md2$ git rebase --continue
Part 6: Complete PR Workflow
Simulate PR Flow
bash1$ git checkout main2$ git checkout -b feature/pr-simulation34$ echo "PR content" >> pr-file.md5$ git add pr-file.md6$ git commit -m "feat: add PR content"78$ git push -u origin feature/pr-simulation 2>/dev/null || echo "No remote, simulating..."
Update and Resolve
bash1# Meanwhile, main gets updated2$ git checkout main3$ echo "Main update" >> main-file.md4$ git add main-file.md5$ git commit -m "update main"67# Your branch needs updating8$ git checkout feature/pr-simulation9$ git fetch origin 2>/dev/null || echo "No remote"10$ git rebase main1112# If conflicts, resolve them13# Then force push14$ git push --force-with-lease origin feature/pr-simulation 2>/dev/null || echo "Simulated push"
Cleanup
bash1$ cd ..2$ rm -rf conflict-practice
Checklist
- Created two branches with conflicting changes
- Merged first branch successfully
- Hit conflict on second branch merge
- Resolved merge conflict manually
- Completed merge with resolution
- Experienced rebase conflict
- Resolved rebase conflict and continued
- Used
--force-with-leaseafter rebase - Configured and used a merge tool
Conflict Resolution Summary
| Situation | Steps |
|---|---|
| During merge | Edit file → git add → git commit |
| During rebase | Edit file → git add → git rebase --continue |
| Use their version | git checkout --theirs file |
| Use our version | git checkout --ours file |
| Abort merge | git merge --abort |
| Abort rebase | git rebase --abort |
Key Takeaway
Conflicts are a normal part of collaboration. The resolution process is always: identify conflicts, edit files to remove markers and create desired content, stage resolutions, then complete the merge/rebase. Practice makes this process second nature.