Resolve Git Merge Conflicts
Step-by-step guide to identify, resolve, and complete merge conflict resolution in Git.
# 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 # theirsUse 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.
Undo Last Git Commit (Soft and Hard)
Git commands to undo the last commit while keeping changes staged, unstaged, or fully discarded.
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
Git Cherry-Pick Commits Example
Apply specific commits from one branch to another using cherry-pick with conflict resolution.
Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.