I am using capistrano to deploy a RoR application. The codebase is in a git repository, and branching is widely used in development. Capistrano uses deploy.rb
f
This solution should work with all versions of Capistrano.
def branch_name(default_branch)
branch = ENV.fetch('BRANCH', default_branch)
if branch == '.'
# current branch
`git rev-parse --abbrev-ref HEAD`.chomp
else
branch
end
end
set :branch, branch_name('master')
Usage:
BRANCH=. cap [staging] deploy
# => deploy current branch
BRANCH=master cap [staging] deploy
# => deploy master branch
cap [staging] deploy
# => deploy default branch