20

I have applied the following commands, but have little confusion in doing rebase - what is ours and theirs in the following commands

git checkout app/dashboard-sprint-5
git rebase app/demandware

I know the current branch is app/dashboard-sprint-5 and when i apply the rebase.

app/dashboard-sprint-5 will be applied on the top of app/demandware.

What is ours and theirs in terms of branches.

I have checked the link but not satisfied

Shan Khan
  • 9,667
  • 17
  • 61
  • 111

2 Answers2

27

Briefly, when we are talking about rebase, ours means the base branch.

So in your case ours will be app/demandware, since firstly git moves us there, and then applies changes from the app/dashboard-sprint-5, which will be theirs.

For example, here the note from documentation about rebase and ours word:

Because git rebase replays each commit from the working branch on top of the <upstream> branch using the given strategy, using the ours strategy simply discards all patches from the <branch>, which makes little sense.

James Wright
  • 1,293
  • 2
  • 16
  • 32
mmelnik
  • 583
  • 5
  • 12
  • 6
    This is literally the first time this has made sense to me and I have being resolving conflicts for years. I always choose the wrong option but not anymore. – CodeMonkeyG Sep 16 '18 at 00:20
7

In order to easily remember the direction of ours and theirs, think of rebasing as cherry-picking each commit of the current branch onto the target branch.

Before rebasing:
    A--B--C (master)
       '--D--E (devel, HEAD)

Reset HEAD to master:
    A--B--C (master, HEAD)
       '--D--E (devel)

Cherry-pick D, E.
    A--B--C (master)
       |  '-- D'--E' (HEAD)
       '--D--E (devel)
HEAD becomes "ours" and the old devel branch "theirs".
              ^^^^                            ^^^^^^

On success, repoint devel to E':
    A--B--C (master)
          '--D'--E' (devel, HEAD)

In a non-interactive rebase that goes through without conflicts, it looks like we jump straight from the old devel-branch history to the rebased devel-branch history. In this view the inversion of ours and theirs isn't apparent, leading to potential confusion, especially also during merge conflict resolution – it is simply a bit unexpected, that the branch we started from may suddenly be called "remote branch" by merge tools.


Though this question was already answered, I add this more visual explanation, since I found it difficult to remember the result without.

kdb
  • 4,098
  • 26
  • 49