Lets see. (this assumes your remote is named origin
)
git fetch origin master
git rebase origin/master develop
git checkout master && git merge --ff-only develop
git push
notes:
git rebase origin/master develop
is exactly the same as git checkout develop && git rebase master
I use --ff-only
when merging for clarity because this merge will not create any new commits, just move the branch pointer.
Ok, so the initial new code is still 4 lines, but checkout appears only once.
You may be able to reduce the checkouts slightly by using ideas from this question, but I will ignore that.
You can further reduce your typeing (but not git execution time), by creating a git alias with multiple commands (as seen here) by starting the alias with an exclamation mark(!
).
You could create an alias like so:
git config --global alias.pushDevelop '!git fetch origin/master; git rebase origin/master develop; git checkout master; git merge --ff-only develop; git push'
You would then use the command like so: git pushDevelop
.
You could also replace the third line with git branch -f master
, and recreate a master
branch on develop
branch, but that might result in a loss of tracking information. (This command forces the creation of branch master
. The -f
would be required because git can not have two branches with the same name.