I want to understand a bit more on git rebase
.
Assume I have this workflow, would git rebase
be useful here?
And if so, what would be the command to migrate commits X to Z (assuming not using cherry-pick) from MASTER
to BRANCH
.
I want to understand a bit more on git rebase
.
Assume I have this workflow, would git rebase
be useful here?
And if so, what would be the command to migrate commits X to Z (assuming not using cherry-pick) from MASTER
to BRANCH
.
Believe it or not, you are actually rebasing master
on branch
!
Here are the commands you could use to achieve this:
git checkout master # checkout the master branch
git checkout -b newbranch # create new branch based on master
git rebase branch # rebase on 'branch'
Keep in mind I created a new branch called newbranch
which will appear the way you want it. It is up to you as to what you want to do with the original branch
. Now newbranch
will look like this:
A--B--C--D--X--Y--Z
A more typical workflow would be to bring new changes from master
into branch
by rebasing the latter on the former, i.e.:
git checkout branch
git rebase master
This would leave branch
looking like this:
A--X--Y--Z--B--C--D
If you do a git rebase master
(while you have checked out your Branch), you replay the commits of Branch
on top of master
:
A--x--y--z--b'--c'--d' (Branch)
|
(master)
That is helpful in order to make sure the local commit of your Branch
are still compatible with the latest evolution from master
.
Make sure you haven't pushed your Branch
yet, as it changes its history.