How do you rebase the current branch's changes on top of changes being merged in?
Solution 1
You've got what rebase
does backwards. git rebase master
does what you're asking for — takes the changes on the current branch (since its divergence from master) and replays them on top of master
, then sets the head of the current branch to be the head of that new history. It doesn't replay the changes from master
on top of the current branch.
Solution 2
Another way to look at it is to consider git rebase master
as:
Rebase the current branch on top of
master
Here , 'master
' is the upstream branch, and that explain why, during a rebase, ours
and theirs
are reversed.
Related videos on Youtube
Jonathan M Davis
Updated on July 08, 2022Comments
-
Jonathan M Davis almost 2 years
Okay. If I'm on a branch (say
working
), and I want to merge in the changes from another branch (saymaster
), then I run the commandgit-merge master
while on theworking
branch, and the changes get merged in without rebasing the history at all. If I rungit-rebase master
, then the changes inmaster
are rebased to be put on the top of myworking
branch. But what if I want to merge in the changes frommaster
but rebase my changes inworking
to be on top? How do I do that? Can it be done?I could run
git-rebase working
on mymaster
branch to put my changes on top in themaster
branch, but I'd like to be able to do that in myworking
branch, and I have no idea how. The closest that I can think of doing is creating a new branch frommaster
and then rebaseworking
's changes on top of that, but then I'd have a new branch instead of altering theworking
branch. -
hobbs over 12 years@Jonathan it's cool. This is a little bit of a tricky topic. By the way,
git rebase working
would movemaster
's changes (after the point thatworking
branched off) to be on top of theworking
branch — but that's not a very sensible thing to do tomaster
:) -
AVIDeveloper almost 9 yearsThat also explains why LOCAL and REMOTE are reversed. Thanks.
-
VonC almost 9 years@AVIDeveloper on LOCAL and REMOTE, you can also read stackoverflow.com/a/3052118/6309
-
AVIDeveloper almost 9 years@@VonC: Thanks. Yep, after spending an afternoon mumbling to myself "REMOTE is my branch.. LOCAL is not mine", it all sunk in. Honestly, I would've preferred seeing the branch names (or abbrev. SHA) instead of REMOTE/LOCAL/ours/theirs/mine. My thoughts are the same regarding the
git difftool
's horrible left/right. Kinda off topic, but fordifftool
I stick to git-meld and enjoy names like 'working-dir', 'stash@{0}', as so on. -
JavaSa about 6 years@VonC: Can you explain how can it be that after we do:
git checkout branch_to_update git rebase master
I get in git log the commits of master on top of local branch, instead the opposite? -
VonC about 6 years@JavaSa That is strange, unless the rebase was not properly completed? You might need to ask a separate question with more details in it.
-
Carmine Tambascia almost 2 yearsThe problem arise regarding conflicts(file in which have different line conflicting, or code that has been modified in both branch), so resolve them is the most tricky part, as you will need to decide what keep for each file, this is especially true for large changes
-
VonC almost 2 years@CarmineTambascia I agree. git rerere, but ultimately, it is a project management/communication issue, which will help minimize concurrent development on a common file.