Reddirt
Reddirt

Reputation: 5953

Using Rails + Capistrano with Github and multiple branches

In my Rails app, I'm using Git, GitHub, and Capistrano. We have 2 servers (staging and production).

Up to now, I would make code changes on my local machine and push them to GitHub, then during deployment Capistrano would copy to either server from GitHub.

Now I have started using branches with Git. I created 2 branches locally on my machine, dev and prod. I'm the only developer at this point. I currently only have the branch master on GitHub.

Questions:

1) Should I create the dev and prod branches on the existing GitHub rpo or should I have a separate GitHub repo for staging and production?

2) If I do add branches, how would I tell Capistrano to use the dev branch for staging and the prod branch for production?

3) If using separate repos, how do I push a branch to the right one?

Upvotes: 3

Views: 147

Answers (2)

Frederick Cheung
Frederick Cheung

Reputation: 84132

One repo is all you need.

Capistrano has a branch setting that controls the branch to deploy. I usually add

set :branch, ENV['BRANCH'] || 'master'

To my deploy.rb so that I can deploy different branches with

cap staging deploy BRANCH=some_branch

Personally I create a new branch for each release, so that it's very easy to deploy small fixes to production - I just cherry pick to the branch for that release and redeploy that branch.

Upvotes: 0

OneChillDude
OneChillDude

Reputation: 8006

I would not use separate branches for development and production. I would make an 'experimental' branch.

A branch is really designed to be a safe place where you can break off of your master (your working code), and try something experimental. So really master is your production branch, and development is any branch you make off of that. When you've made your changes on your other branch, commit them, and then use

git checkout master

git merge newbranch

to merge the newbranch in to your master.

Upvotes: 1

Related Questions