Using Fabric to deploy current git branch to heroku

fabric, git, heroku, python

Solution

OK - a bit more digging got me this:

from fabric.api import local
my_branch = local('git rev-parse --abbrev-ref HEAD', capture=True)

which does exactly what I wanted.

Problem

I'd like to shorten the process of deploying to Heroku (i.e. a git push) I use git-flow to organise my codebase - so typically the process would be: - start a new feature branch - Do the coding - Push this branch up to my dev heroku instance - `git push develop feature/somefeature:master`) - Merge into the develop branch - Create a new release branch - Push this to the production heroku instance - `git push production release/1.2.3:master` What I'd like to do is be able to run a Fab command like: `fab dev_deploy` which would just deploy whatever the current working branch is to my dev instance and `fab prod_deploy` which would do the same but push to the production instance. I could include some sanity checks here to make sure I'm inside a release branch etc. my fab commands would do other things (like push static assets up to the right S3 bucket etc, run south migrate commands and so on) So all I really want to know is how to get the current working branch as a variable inside fabric...!? Thanks, Guy

Original source