git flow release

Bastardising git flow for release automation

For a number of reasons (some historical, some legacy, some just daft), the optional Interlok components live in various git providers. This isn’t a post that argues that git flow is great; it’s well understood so we use it to remove the friction of understanding a bespoke tagging/branching system. When we do a product release there’s a Jenkins pipeline that builds all the artefacts based on the release branch from git flow release. That means that when we decide that it’s time to prepare for a release, we have to do a git release start on every project and publish that branch; all of which is nice and scriptable.

Sadly though, when we do a git flow release finish, things aren’t that simple as git flow finish does like to have a merge message when you merge into both the master and develop branch. The beauty of git is that all these sub-commands are just shell scripts so all we need to do is patch git-flow-common and git-flow-release so that we don’t have to enter a merge message when that part of the pipeline fires.


First of all, we add a new function to git-flow-common that generates the merge message (available as a diff).

# gitflow_render_merge_message
# Inputs:
# $1 = source branch
# $2 = destination branch
# Renders a pre-defined merge message.
gitflow_render_merge_message() {
  local src_branch=$1
  local dst_branch=$2
  local msg=$(eval "echo $(git config --get gitflow.merge.message)")
  if [ "$msg" != "" ]; then
    echo "$msg"


Then we need to patch the cmd_finish function in git-flow-release so that when a merge is attempted on both the master and develop branches (so it may be 2 places you make some changes). In the end it’ll look something like this (available as a diff) :

 # try to merge into master
 # in case a previous attempt to finish this release branch has failed,
 # but the merge into master was successful, we skip it now
 if ! git_is_branch_merged_into "$BRANCH" "$MASTER_BRANCH"; then
         git checkout "$MASTER_BRANCH" || \
           die "Could not check out $MASTER_BRANCH."

         local msg=$(gitflow_render_merge_message "$BRANCH" "$MASTER_BRANCH")

         if noflag squash; then
                 if [ "$msg" != "" ]; then
                         git merge --no-ff -m "$msg" "$BRANCH" || \
                                 die "There were merge conflicts."
                         git merge --no-ff "$BRANCH" || \
                                 die "There were merge conflicts."
                 # TODO: What do we do now?
                 git merge --squash "$BRANCH" || \
                         die "There were merge conflicts."
                 git commit


Finally you need to modify your local git config so that you define the merge message :

[gitflow "merge"]
        message = Automated Merge of \\'$src_branch\\' into \\'$dst_branch\\'.

©. All rights reserved.

Powered by Hydejack v6.6.1