Deploy once a specific branch with capistrano?

We have a very simple branching strategy:

  • develop -> Development branch
  • staging -> Staging Server Deploy Branch
  • master -> Productio Branch

Our production deploy workflow is develop -> staging -> master. We always deploy first to staging, we test for some time, and then we deploy to production.

  • Sorting out a Git mess
  • Rebasing remote branches in Git
  • Is checking out remote branches in git safe now?
  • Copying an untracked folder to another branch
  • Is a TFS branch a physical or logical snapshot?
  • git change origin of a branch (rebase)
  • Right now we’re working in a new feature that I would like to test. I don’t want to put it in staging because, since is experimental, I would not like to lock a production deploy until the feature is finished.

    Is there a way to say to capistrano the branch I want for one particular deploy, so I could put this experimental code in staging to test it?

    OBS: The reason I need to put in staging is that this piece of code depends on a lot of external resources that are already configured in staging and would be difficult to replicate locally.

  • Ansible: how to run task on other host inside one playbook?
  • Why is a cap deploy giving Permission denied (publickey)?
  • How can I track multiple svn branches in git
  • Github deploy only specific features in development branch
  • Git: merge only the changes made on the branch
  • Are there different meanings to the concept of 'tracking' in git?
  • One Solution collect form web for “Deploy once a specific branch with capistrano?”

    Here’s how I do it.

    At the top of my config/deploy/staging.rb file, I put this:

    set :branch, ENV.fetch("CAPISTRANO_BRANCH", "staging")

    This tells Capistrano that when I run cap staging deploy, use the staging branch by default, but allow that to be overridden by the CAPISTRANO_BRANCH environment variable.

    So now if I want to deploy a custom branch to staging, it is as simple as this:

    CAPISTRANO_BRANCH=my-feature cap staging deploy
    Git Baby is a git and github fan, let's start git clone.