Take the 2-minute tour ×

I have conflicting branches, branch2 branched from branch1.

Let's say when rebasing branch2 on current branch1, while resolving conflicts, I decide to take some (not all) of "their" (i.e. branch1) files as-is. How do I do that?

I tried:

git checkout branch1:foo/bar.java
fatal: reference is not a tree: TS-modules-tmp:foo/bar.java

git checkout refs/heads/branch1:foo/bar.java
fatal: reference is not a tree: refs/heads/TS-modules-tmp:foo/bar.java
share|improve this question
Note: if you're rebasing branch2 onto branch1, the replaying happens relative to branch1, so "theirs" is actually branch2 and "ours" is branch1. git.661346.n2.nabble.com/… –  Mr Fooz May 29 '12 at 22:20
add comment

3 Answers

up vote 48 down vote accepted

I think you are looking for

git checkout --theirs foo/bar.java
git add foo/bar.java

Then you can git rebase --continue after you've resolved all conflicts.

Edit 7/16/2013: I believe my answer is correct for the question asked. The question asked is how to choose branch1's version when rebasing branch2 on branch1. When rebasing branch2 onto branch1, branch1's commits are unwound up to the parent node and branch2's commits are pushed onto branch1, then branch1's commits are added on top of branch2's commits. In the case of a conflict, branch2's commits are ours and branch1's commits become theirs. I realize this is a bit confusing, but I just tried it in a test repository and it works like I describe.

It is possible when the question asks, "I decide to take some (not all) of "their" (i.e. branch1)", it is certainly possible that the mapping of "their" to "branch1" was unintended, but actually correct.

share|improve this answer
snap and before me :-) –  Adrian Cornish Nov 16 '11 at 6:10
Is there any way to avoid "fatal: --ours/--theirs is incompatible with switching branches."? –  Mr Fooz May 29 '12 at 22:19
I'm not familiar with this error. Does this happen while resolving merge conflicts? Are you using any other arguments to the checkout command? The switching branches message seems odd, are you specifying -b to git checkout? I apologize if this is not much help :-( –  Nathan Fox May 30 '12 at 21:25
--theirs is exactly wrong during rebase, which is completely counterintuitive, but IGEL has it right below. –  slinkp Jan 24 '13 at 5:05
This caused some trouble for me, @iGEL has it right below. –  calvintennant Jul 16 '13 at 20:19
add comment

As Mr Fooz said, you probably want to use

git checkout --ours foo/bar.java
git add foo/bar.java

If you rebase a branch feature_x on master, during rebasing ours refers to the master and theirs to feature_x. See http://git.661346.n2.nabble.com/Counter-intuitive-results-for-git-show-and-git-checkout-during-rebase-with-conflict-td2370354.html

share|improve this answer
add comment

If you want to pull a particular file from another branch just do

git checkout branch1 -- filenamefoo.txt

This will pull a version of the file from one branch into the current tree

share|improve this answer
This would probably be a bad idea in the middle of a rebase as it would pull the file from the head of that branch not at the detached head point you would be at in a conflicted rebase state –  Clintm Sep 19 '13 at 21:39
add comment

Your Answer


