If using a development process that consists of multiple stages of maturity, development mainly progresses in one branch only. I often use a process that consists of the three branches ‘develop’, ‘staging’ and ‘master’, so in my case the development mainline is ‘develop’. You might want to check out my post on how to enforce or safeguard such a development process.

If the development process also advocates the use of feature branches, the ‘develop’ branch often is in a state that is mature enough to be merged into the upper branch.

To aid in this process I developed a little script to merge the current branch into the upper branch. The script removes the need to issue a bunch of Git commands and performs the following tasks:

• check for unclean working copies prior merging
• checkout target branch and pull from origin
• merge from lower branch
• push to origin
• repeat the last three steps for the branch higher than the target branch

The script asks for confirmation before every action and assumes relatively save defaults (it’s e.g. not the default to directly merge up into master/production).

The script works for a process with three stages (‘develop’, ‘staging’, ‘master’) as well as for one with two stages (‘develop’, ‘master’) – the stages must be named as described, however.

The script is executed by just calling merge-up when in a Git working copy that has either the branch ‘develop’ or ‘staging’ checked out.