Git Merge Conflicts: How to Keep Ours or Theirs
During a merge conflict, git checkout --ours file keeps your branch’s version and git checkout --theirs file keeps the incoming branch’s version. Then git add the file and commit. One thing catches almost everyone out: during a rebase, ours and theirs are reversed.
Quick answer
git checkout --theirs config.js # or --ours
git add config.js
git commit --no-edit # finish the merge

How we tested: every command on this page was run in a real Git repository (Git 2.43) on 18 November 2026, and the output shown is copied from the terminal. Your commit hashes will differ.
What a conflict looks like
main raised a price to 12 while feature/sale lowered it to 8, on the same line:
$ git merge feature/sale
Auto-merging config.js
CONFLICT (content): Merge conflict in config.js
Automatic merge failed; fix conflicts and then commit the result.
$ git status --short
UU config.js
$ cat config.js
<<<<<<< HEAD
price = 12
=======
price = 8
>>>>>>> feature/sale
UU means both sides changed the file. Between <<<<<<< HEAD and ======= is your current branch (“ours”); between ======= and >>>>>>> feature/sale is the branch you’re merging in (“theirs”).
You have three options: edit the file by hand and keep whatever mix is right, take one whole side, or abort.
Keep one side for a file
If you know one version is correct for the entire file, don’t edit markers by hand:
$ git checkout --theirs config.js
Updated 1 path from the index
$ cat config.js
price = 8
$ git add config.js
$ git commit --no-edit
[main a061664] Merge branch 'feature/sale'
$ git log --oneline -1
a061664 Merge branch 'feature/sale'
The file now holds the sale price only, the markers are gone, and the merge is finished. Use --ours to keep your branch’s version instead. This works per file, so you can take theirs for one file and ours for another in the same merge.
--theirs replaces the entire file with their version, including parts that merged cleanly from your side. If you only want their side of the conflicting lines, edit by hand or use a merge tool (VS Code shows “Accept Current / Incoming / Both” buttons above each conflict).Prefer one side for the whole merge
If you already know you’ll want your side for every conflict, tell Git up front with -X ours (or -X theirs):
$ git merge -X ours feature/sale -m 'Merge sale, keep our prices'
Auto-merging config.js
Merge made by the 'ort' strategy.
$ cat config.js
price = 12
No conflict stop at all. Only the conflicting lines went our way; changes from feature/sale that didn’t clash still merged in. That’s the difference from -s ours (a lowercase s), which ignores the other branch completely and is rarely what you want.
Why ours and theirs flip during a rebase
A rebase replays your commits on top of the other branch. So while it runs, the branch you’re rebasing onto is the base (“ours”) and your commits are being applied to it (“theirs”). Real output from rebasing feature/sale onto main:
$ git rebase main
Auto-merging config.js
CONFLICT (content): Merge conflict in config.js
error: could not apply 6ac1794... Sale price
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 6ac1794... Sale price
$ git checkout --ours config.js
Updated 1 path from the index
$ cat config.js
price = 12
$ git rebase --abort
We were on feature/sale (price 8), yet --ours gave us 12, the value from main. If you want to keep your own commit’s version during a rebase, use --theirs. Same file, same command, opposite meaning. After choosing, git add the file and run git rebase --continue.
During git merge |
During git rebase |
|
|---|---|---|
--ours |
The branch you’re on | The branch you’re rebasing onto |
--theirs |
The branch you’re merging in | Your commits being replayed |
Get out of a merge entirely
$ git merge feature/sale
Auto-merging config.js
CONFLICT (content): Merge conflict in config.js
Automatic merge failed; fix conflicts and then commit the result.
$ git merge --abort
$ git status --short
An empty status means you’re back to exactly where you were before git merge. The same exists for other operations: git rebase --abort, git cherry-pick --abort, git revert --abort.
Fewer conflicts next time
- Pull or rebase onto
mainoften. Small, frequent merges conflict less than one huge one. - Keep formatting changes (whole-file reformatting, line endings) in their own commits.
- Turn on
git config --global rerere.enabled true: Git then remembers how you resolved a conflict and repeats it if the same one comes back.
Related guides
- git cherry-pick: Copy a Commit to Another Branch
- git revert: Undo a Commit Without Rewriting History
- git fetch vs git pull
- All Git commands with examples
FAQ
What is the difference between ours and theirs in Git?
In a merge, “ours” is the branch you’re on and “theirs” is the branch being merged in. In a rebase they’re reversed.
How do I accept all incoming changes in a merge conflict?
Per file: git checkout --theirs <file>, then git add. For the whole merge: git merge -X theirs <branch>.
How do I cancel a merge with conflicts?
Run git merge --abort. It returns your branch to the state before the merge.
What is the difference between -X ours and -s ours?
-X ours only decides conflicting lines in your favour and still merges everything else. -s ours ignores the other branch’s changes completely.