Fullybaked-logo

fullybaked | davebaker

I'm a developer living in the UK and when I'm not spending time with my wife and our 2 wonderful little boys, I love hacking around with code

I'm passionate about technology, web development, gaming and fencing

25 February 2013

Use current Git branch for deploy in Capistrano

I use Git Flow and Capistrano Multistage to manage deployment of my web apps, which means I can be deploying lots of different branches to our test server through out the day if we are doing patches and feature development intermingled with each other.

Originally I was just changing the branch name in the test.rb file each time I needed to deploy a different branch, but eventually I got fed up with it.

This little method will help deploy the currently checked out branch each time. Just add it to your deploy script

def git_branch
  `git symbolic-ref HEAD`.gsub(/^refs\/heads\//, '').chomp
end

Then just change the deploy recipe to use the method instead of a branch name

set :branch git_branch