Deploy a specific git branch via capistrano to a staging server

I have my master branch that is used to deploy to a staging server. And I have my stable branch that is used to deploy to the production server. The capistrano script I use is setup this way.

Current workflow:
Whenever there is an issue with production, I branch out from stable branch, fix things up, commit it, merge it with stable and then deploy to production.

This gives no chance for me to test that bug fix (happened in that hot fix branch), in my staging server. Ideally what I want would be:

Wanted workflow:
Whenever there is an issue with production, I branch out from stable branch, fix things up, commit it, merge it with master, deploy and test that fix in staging server, validate if it works, then merge that hot fix branch to stable and deploy it the production.

How do I get this right with Capistrano? Please help.

  • Rails 4 / Capistrano 3 Deployment Stopped Working (no errors)
  • Why does rails remember deleted css?
  • Setting up staging environment for heroku app
  • How do I use git to manage a codebase with separate client assets?
  • Git on InstantRails
  • how to set visible .gitignore in IDE Aptana Studio?
  • Unable to push 'heroku master'
  • Capistrano release not publishing
  • 2 Solutions collect form web for “Deploy a specific git branch via capistrano to a staging server”

    Disclaimer: Forgive me if i’ve misunderstood your question, but i think you’ve already answered you own question.

    Your Git workflow is just that, your ‘git workflow’. Doesn’t really have anything to do with Capistrano. Capistrano will fetch whatever you want it to, it’s up to you how you want to merge and branch your repo to get it to the point of deployment.

    From what you said i’m assuming you have your cap stages setup already to deploy the right branch, but if you don’t there is an example below. This will fetch the different branch for each type of deploy.

    deploy.rb

      set :stages, %w(staging production)
      set :default_stage, "staging"
    

    deploy/staging.rb #cap deploy

      set :branch, 'master'
    

    deploy/production.rb #cap production deploy

      set :branch, 'stable'
    

    Here’s a flow that will let you test on staging and still leverage your existing capistrano deploy configuration. I’m assuming here that your staging branch is ahead of master and that Capistrano is setup with the multi-staging extension.

    1. From master, create a hot fix branch, I use a naming convention for hot fix, for example hotfix-20121203

      git checkout -b hotfix-20121203 
      
    2. merge your hot fix branch into staging, deploy and test staging

      git checkout staging
      git merge hotfix-20121203
      cap staging deploy
      
    3. merge your hot fix branch into master, deploy and test master

      git checkout master
      git merge hotfix-20121203
      cap production deploy
      
    Git Baby is a git and github fan, let's start git clone.