37

I'm completely confused about what mine vs theirs means. In this specific case, I've got a feature branch where I just squashed about 80 commits via rebase -i and am merging this back into develop. I got a few conflicts, and I just want to use whatever code is on my feature branch. I tried "mine" but that actually seemed to do the opposite.

Could someone shed some light on this terminology?

CaptSaltyJack
  • 15,283
  • 17
  • 70
  • 99

3 Answers3

65

ours and theirs is a somewhat confusing concept; exacerbated when performing a rebase:

When performing a merge, ours refers to the branch you're merging into, and theirs refers to the branch you are merging from. So if you are trying to resolve conflicts in the middle of a merge:

  • use ours to accept changes from the branch we are currently on
  • use theirs to accept changes from the branch we are merging into.

That makes sense, right?

When rebasing, ours and theirs are inverted. Rebases pick files into a "detached" HEAD branch. The target is that HEAD branch, and merge-from is the original branch before rebase. That makes:

  • --ours the anonymous one the rebase is constructing, and
  • --theirs the one being rebased;

I.e., rebasing replays the current branch's commits (one at a time) on top of the branch that we intend to rebase with.

Keith
  • 3,079
  • 2
  • 17
  • 26
  • 16
    You say "theirs refers to the branch you are merging *from*" and then "use theirs to accept changes from the branch we are merging *into*" - huh? – M.M Aug 04 '15 at 21:00
  • 2
    Poor use of the term "into". If I'm on a branch, and want to merge with master, running "Git checkout --theirs filename(s)" will give master's files precedence, this overwriting my branch's copies. "--ours" is the opposite, giving my branch precedence in the merge – Keith Aug 05 '15 at 00:58
  • 8
    Hmm, I find the question which perfectly matches my confusion. I read the well-voted answer several times, and still don't know the answer to any level of confidence. Back to Google. – HeyHeyJC Apr 15 '18 at 16:19
  • @HeyHeyJC I can try to rephrase if you can articulate specifics of what’s unclear – Keith Apr 15 '18 at 16:24
  • 1
    Confusion comes from 'the branch we are currently on' and 'the branch we are merging into' being the same thing. I think what you mean for the second one is 'the branch we are merging into the branch we are on'. I think a clearer way of saying the second case is 'to accept the changes from the branch you are merging' – Aerankas Dec 12 '18 at 22:35
  • 3
    All contradictory answers. When you are in Gitlab making a merge from a branch comparison, you are not actually "into" any branch in particular, at least you don't explicitly know. "Source" and "target" branch would be more explicit terms when you are not using the command line. – Juan Oct 08 '19 at 12:11
23

"Ours" (and "mine") refer to the current branch; "theirs" refers to the branch being merged in. It sounds like you actually wanted to use "theirs".

mipadi
  • 398,885
  • 90
  • 523
  • 479
0

I admit it is confusing at first . I even wrote an article about this to explain in detail how this works.

In short: "mine" is the change you're holding in your branch, "theirs" is the target branch that everything is going into.

EeKay
  • 6,494
  • 3
  • 24
  • 24