Skip to main content

A quick bash script to make feature branching a bit easier

An article from ComputerMinds - Building with Drupal in the UK since 2005
8th Feb 2018

Mike Dixon

Senior Mind
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?

During a typical working day I can easily flip between 15 projects, fixing small bugs or working on various features.  Each flip normally requires a new feature branch, and i found myself repeating myself.  A lot.  I'm a parent so I'm pretty used to this, but in this instance I figured I could probably do something about it - so put together a simple bash script.

#!/bin/bash

git pull
git checkout -b feature/$1
git push origin feature/$1
git branch --set-upstream-to origin/feature/$1

This will do a pull on the current branch, create a new feature branch (using the name I pass in as an argument) before pushing the branch up to github and then setting the upstream origin.

I originally had a git checkout production line at the top, but then figured actually I needed to take my feature branch of master sometimes so removed that.

So now - when I jump onto ticket 12345 - I just run

git checkout production
go 12345-my-branch-name

And hey presto - all ready to do some actual coding.

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.