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 haven't properly understood.
When rebasing, who is 'local' and who is 'remote'?
(I use P4Merge for resolving conflicts)
The bottom line
git rebase
git merge
In other words, LOCAL is always the original, and REMOTE is always the guy whose commits weren't there before, because they're being merged in or rebased on top
Prove it!
Certainly. Don't take my word for it! Here's an easy experiment you can do to see for yourself.
First, make sure you have git mergetool configured properly. (If you didn't, you probably wouldn't be reading this question anyway.) Then find a directory to work in.
Set up your repository:
Create an initial commit (with an empty file):
Create a commit on a branch that isn't master:
Create a commit on the master branch:
At this point your repository should look like this:
Now for the rebase test:
Now the merge test. Close your mergetool without saving any changes, and then cancel the rebase:
Then:
Your results should be the same as what's shown up top.
I didn't get your problem exactly but I think the following diagram resolves your issue. (Rebase : Remote Repository ---> Workspace)
Source: My Git Workflow
TL;DR;
To summarize (As Benubird comments), when:
local
isB
(rebase onto),remote
isA
And:
local
isA
(merge into),remote
isB
A 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
ours
andtheirs
during a rebase.(relevant extracts)
git rebase
man 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 upstream
will first changeHEAD
of 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 mergetool
does 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: