bashintermediate

Resolve Git Merge Conflicts

Step-by-step guide to identify, resolve, and complete merge conflict resolution in Git.

bash
# Start a merge that may have conflicts
git merge feature/new-feature

# Check which files have conflicts
git status

# Conflict markers in files look like:
# <<<<<<< HEAD
# your changes
# =======
# incoming changes
# >>>>>>> feature/new-feature

# After manually resolving conflicts in your editor:
git add resolved-file.ts

# Complete the merge
git commit

# Abort the merge and go back to pre-merge state
git merge --abort

# Accept all incoming changes for a file
git checkout --theirs path/to/file.ts
git add path/to/file.ts

# Keep your version of a file
git checkout --ours path/to/file.ts
git add path/to/file.ts

# Use a merge tool
git mergetool

# View the base, ours, and theirs versions
git show :1:file.ts  # base
git show :2:file.ts  # ours
git show :3:file.ts  # theirs

Use Cases

  • Resolving conflicts during branch merges
  • Handling rebase conflicts step by step
  • Team collaboration on overlapping code

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.