0

My current master-based workflow is to develop hotfixes in master and new features in develop branch. When it's time to release I do the following:

git checkout master && git pull
git checkout develop && git rebase master
git checkout master && git merge develop
git push

Can I do the same with fewer commands? I would like to omit multiple checkouts if possible.

Pavlo
  • 43,301
  • 14
  • 77
  • 113

1 Answers1

1

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.

Community
  • 1
  • 1
Thomas F
  • 1,869
  • 3
  • 24
  • 25