How do I resolve a git merge conflict?
Short answer
Git marks the conflicting region with <<<<<<<, ======= and >>>>>>>. Edit the file so it contains what you want, delete the markers, git add it, and commit.
<<<<<<< HEAD
const timeout = 30;
=======
const timeout = 60;
>>>>>>> feature-branch- Between
<<<<<<<and=======is your version (the branch you are on). - Between
=======and>>>>>>>is theirs (the branch being merged in).
Edit the region to the correct final content — which may be one side, the other, or a combination — and delete all three marker lines.
git add conflicted-file.js
git commit # git pre-fills a merge message#Finding them all
git status # lists unmerged paths
git diff --name-only --diff-filter=U#Taking one side wholesale
git checkout --ours path/to/file # keep your version
git checkout --theirs path/to/file # keep theirs
git add path/to/fileCareful during a rebase: "ours" and "theirs" swap meaning, because your commits are being replayed onto the other branch. Check with git status before assuming.
#Backing out
git merge --abort
git rebase --abortReturns everything to how it was before you started.
#Reducing how often it happens
- Merge or rebase from main frequently, so branches never drift far apart.
- Keep branches short-lived and focused.
- Agree on formatting and enforce it automatically — most gratuitous conflicts are whitespace.
#Turn on rerere
git config --global rerere.enabled true"Reuse recorded resolution" remembers how you resolved a conflict and replays it automatically next time. It pays for itself on the first long-running rebase.