Reputation: 23
I have situation like this:
H---I---J feature2
/
E---F---G feature1
/
A---B---C---D master
I want to keep my master up-to-date since it is changing very frequently while working on the features. My current way of work is as follows:
git checkout master
git pull
git checkout feature1
git rebase master
git checkout feature2
git rebase feature1
Is there any simpler way to do all these steps? I'm using latest sable git version. Also, I sometimes have situation like this with even 6 feature branches, so it would be great if any solution would be extensible for many feature branches on top of another.
Upvotes: 2
Views: 971
Reputation: 265141
As of Git 2.38.0, rebase has learned the option --update-refs
and your task becomes as easy as:
git rebase --update-refs master feature2
This will rebase feature2
onto master
and at the same time update refs that pointed to the original commits to point to the new, rebased commits instead.
Upvotes: 2
Reputation: 1323203
Actually, rebasing just feature2
would also rebase feature1
, in that it would duplicate its commits and replay them onto master
.
You could then reset feature1
to its new HEAD commit, located 'n' commits before feature2
HEAD.
And you can first count the number of commits of feature2
with:
git checkout feature2
git rev-list --count HEAD ^feature1 # memorize that in 'n'
Then rebase (no need to checkout master and pull):
git fetch
git rebase origin/master
H'---I'---J' feature2
/
master E'---F'---G'
| /
A---B---C---D--Y--Z origin/master
\
E--F--F (feature1)
Finally reset feature1
git branch -f feature1 feature2~n
So, if we extend that scenario to 6 branches:
In any case, that would need to be scripted in order to scale.
Upvotes: 3