Bart Dorsey

Resolving Conflicts Step by Step

Step-by-Step Process

1. Identify Conflicts

git status
# Shows files with conflicts in red

2. Open Conflicted Files

Look for conflict markers (<<<<<<<, =======, >>>>>>>)

3. Understand Both Changes

4. Resolve the Conflict

Choose one of these approaches:

5. Remove Conflict Markers

Ensure all <<<<<<<, =======, and >>>>>>> markers are removed.

6. Test Your Resolution

7. Stage and Commit

git add <resolved-files>
git commit -m "Resolve merge conflicts in [describe what was resolved]"

Best Practices to Minimize Conflicts

Communicate — Inform team members when working on shared files. Use feature branches for isolated development and have clear code ownership areas.

Update frequently:

git fetch origin
git merge origin/main  # or git rebase origin/main

Make small, focused commits — One change at a time with clear commit messages. Avoid large, sweeping changes.

Stay consistent — Use formatters (Black for Python, Prettier for JS) and linters to prevent style conflicts before they happen.


Common Commands

# Abort a merge if things go wrong
git merge --abort

# View the conflict in a three-way diff
git diff --ours   # Your version
git diff --theirs # Their version

# After resolving, continue with rebase
git rebase --continue

# Check what files have conflicts
git diff --name-only --diff-filter=U

# Use a merge tool
git mergetool

Troubleshooting

“I accidentally committed conflict markers”

git add <fixed-files>
git commit --amend

Only do this if you have not yet pushed your changes.

“I’m lost in a complex conflict”

git merge --abort

“I want to see what changed”

git log --oneline --graph --all
git show <commit-hash>

Git conflicts are a normal part of collaborative development. The key is to stay calm, be methodical, and remember that Git always keeps your code safe — you can always recover from mistakes.