When doing a git rebase, I often have difficulty working out what is happening with the ‘local’ and ‘remote’ when resolving conflicts. I sometimes have the impression that they swap sides from one commit to the next.
This is probably (definitely) because I still don’t properly understand the paradigm.
When rebasing, who is ‘local’ and who is ‘remote’?
(I use P4Merge for resolving conflicts.)
TL;DR;
To summarize (As Benubird comments), when:
localisB(rebase onto),remoteisAAnd:
localisA(merge into),remoteisBA rebase switches
ours(current branch before rebase starts) andtheirs(the branch on top of which you want to rebase).kutschkem points out that, in a GUI mergetool context:
ours” (the upstream branch)theirs” – the current branch before the rebase.See illustrations in the last part of this answer.
Inversion when rebase
The confusion might be related to the inversion of
oursandtheirsduring a rebase.(relevant extracts)
git rebaseman page:Because of this, when a merge conflict happens:
ours‘ is the so-far rebased series, starting with<upstream>,theirs‘ is the working branch.In other words, the sides are swapped.
Inversion illustrated
On a merge
, we don’t change the current branch ‘B’, so what we have is still what we were working on (and we merge from another branch)
On a rebase:
But on a rebase, we switch side because the first thing a rebase does is to checkout the upstream branch! (to replay the current commits on top of it)
A
git rebase upstreamwill first changeHEADof B to the upstream branchHEAD(hence the switch of ‘ours’ and ‘theirs’ compared to the previous “current” working branch.), and then the rebase will replay ‘their’ commits on the new ‘our’ B branch:
Note: the “upstream” notion is the referential set of data (a all repo or, like here, a branch, which can be a local branch) from which data are read or to which new data are added/created.
‘
local‘ and ‘remote‘ vs. ‘mine‘ and ‘theirs‘Pandawood adds in the comments:
GUI git mergetool
kutschkem adds, and rightly so:
ours” (the upstream branch)theirs” – the current branch before the rebase.git mergetooldoes indeed mention ‘local’ and ‘remote’:For instance, KDiff3 would display the merge resolution like so:
And meld would display it too:
Same for VimDiff, which displays: