How To Get Current Currently Checked Out Git Branch Without Feature

Here at Otreva we are big fans of GIT and also the Gitflow workflow. We were recently creating an Atlassian Bamboo continuous integration plan on our OS X Mac builder which needed to know what currently checked out GIT branch was currently being built since we are using Bamboo’s automatic branching feature. We were then building the branch name direct to an AWS Elastic Beanstalk environment from the specific checkout out GIT branches so we needed their names to be less than 23 characters and have all “/” stripped due to AWS guidelines for environment naming.

The below command will allow you to get the currently checked out GIT branch as denoted with a * and also trim out and Gitflow branch naming before “/” like release/ or feature/ and also trip down to 22 characters.

branch=$(git branch|grep \*|sed 's/\*//'|sed 's/ //'|sed 's/\(.*\/\)//'|cut -c 1-12);

which you can then write to a file.

echo "branch = $branch" > "./bamboo.properties"

And it can be read with the Bamboo Inject Variables Plugin created by Atlassian Labs.

{o}
Otreva is a custom software product development company focusing on user experience, responsive web development, & mobile application development.

Interested in seeing what it costs to build an app?

Start Quote See Stats
224 Wyoming Ave. #100
Scranton, PA 18503

You've found the secret footer!

Tweets about @Otreva

Or check us out on:

Shopify Experts
Awwwards