1

I am not an expert in Git, but I have seen this done before (I just didn't know the actual implementation behind it).

I have my main website at www.foobar.com but I want to have a testing subdomain at beta.foobar.com (or if that's too complicated, a testing dir at foobar.com/beta)

Is there a way to have 2 branches in my Git repo that manage the main website and a subdomain so that I can do all my testing in beta, and when I find my code satisfactory, I can simply merge beta in the master branch?

If I am thinking about this problem the wrong way, please feel free to propose an alternative. Thanks!

Bert B.
  • 579
  • 2
  • 12
  • 26

1 Answers1

2

This is pretty easy to achieve and is nothing specific to GIT, but depends on your webserver settings and the deployment process for your app. 2 easy steps:

  1. Configure your web server to serve both www.foobar.com and beta.foobar.com. Serve the different domains from different web-roots, e.g. main app from /var/www/foobar.com/app/public and subdomain from /var/www/foobar.com/subdomains/beta/public
  2. For deployment, simply clone the master branch into .../app/public directory and the beta branch into .../subdomains/beta/public

The process can also be automated with tools like Capistrano and the multistage extension.

EDIT in response to your comment:

In a serious project that you are not just doing for yourself, you should never update the files that are currently deployed. Here is the proposed setup:

  1. Have a bare git repository - either accessible on your server or on github.com (or any other provider)
  2. Clone the repository on your development machine - this is the code you'll be working on
  3. Suppose a change in the beta branch: push that change
  4. Now you can clone your beta branch of the bare repository into your deployment path for beta
  5. Whenever you feel ready: pull beta into master (on your dev machine)
  6. Push master
  7. Deploy master by cloning bare repository master branch into deployment path for master

As noted above, tools like capistrano make deployment dead simple and they can even keep a history of your different deployments. Look at this post for example to see how it is used for PHP deployments.

emrass
  • 6,253
  • 3
  • 35
  • 57
  • I'm running into an issue where the beta and master branches aren't seeing each other. If I clone the beta branch into the beta folder, make a change, and go to merge it, there is only the beta branch available in that folder. If I go back to the master branch, want to merge the changes from the beta branch, it doesn't see the changes (because the .git folders are in different locations, I'm assuming). Any other suggestions? – Bert B. Jun 23 '12 at 15:04
  • Edited my answer to reflect your comment. – emrass Jun 23 '12 at 22:49