Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to automate the Git Flow tag/release process
#!/bin/bash
# current Git branch
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
# v1.0.0, v1.5.2, etc.
versionLabel=v$1
# establish branch and tag name variables
devBranch=develop
masterBranch=master
releaseBranch=release-$versionLabel
# create the release branch from the -develop branch
git checkout -b $releaseBranch $devBranch
# file in which to update version number
versionFile="version.txt"
# find version number assignment ("= v1.5.5" for example)
# and replace it with newly specified version number
sed -i.backup -E "s/\= v[0-9.]+/\= $versionLabel/" $versionFile $versionFile
# remove backup file created by sed command
rm $versionFile.backup
# commit version number increment
git commit -am "Incrementing version number to $versionLabel"
# merge release branch with the new version number into master
git checkout $masterBranch
git merge --no-ff $releaseBranch
# create tag for new version from -master
git tag $versionLabel
# merge release branch with the new version number back into develop
git checkout $devBranch
git merge --no-ff $releaseBranch
# remove release branch
git branch -d $releaseBranch
@bclinkinbeard

This comment has been minimized.

Copy link
Owner Author

bclinkinbeard commented Nov 1, 2011

Usage from Terminal:

./release.sh 1.0.0
./release.sh 1.5.7

Some things to note:

  • Line 7 specifies that your tag names will include a 'v' before the number. Remove the 'v' if desired.
  • Lines 18 must point to a valid file path
  • Line 22 expects to find text like "= v1.3.6", and will replace the number with the one you specified as an argument. Modify sed command as necessary/desired.
@alexkubica

This comment has been minimized.

Copy link

alexkubica commented Jan 9, 2017

This is interesting, do you have an actual project where you use it? I also need to maintain a changelog and docs version, I may implement it this way.

@nagaraju-1982

This comment has been minimized.

Copy link

nagaraju-1982 commented Feb 2, 2017

shall i add this script in groovy for pipeline for automatic branch cut and build management????please suggest

@kishore-pandiri

This comment has been minimized.

Copy link

kishore-pandiri commented Dec 21, 2017

These changes , how do i apply to Repo level , Can i use any specific command ? Please advice

@neosavvy

This comment has been minimized.

Copy link

neosavvy commented Sep 4, 2018

Funny that I just stumbled on this @bclinkinbeard - hope all is well man. I just did a google search for exactly what you have in this gist. I'll probably do something very similar to get some basic info into my build-info for docker containers and my react app.

Thanks!

@denisvely

This comment has been minimized.

Copy link

denisvely commented Sep 12, 2018

Thank you !

@vavachi

This comment has been minimized.

Copy link

vavachi commented Mar 17, 2019

Thank you 👍

@wisdom-17

This comment has been minimized.

Copy link

wisdom-17 commented Aug 2, 2019

@bclinkinbeard - Thanks for this.

what is the purpose of line 4? Doesn't look like it's being used anywhere in the script

"# current Git branch
branch=$(git symbolic-ref HEAD | sed -e 's,./(.),\1,')"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.