Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Well, this is an idea that came to my mind a couple days ago and I could figured out how to do it (and even if it would be possible).

My idea would displaying a different branch when you access the website with a different address. For example :

  • would use the master branch

  • would use another one

So, here it is. Don't know if it would be possible, but, who knows :)

share|improve this question
up vote 2 down vote accepted

Yes, this can be done.

You'll need to configure Apache to point each domain to the appropriate subdirectories within the repository. You can use the --shared option of git-clone to keep from duplicating the backing files. Make sure you configure Apache to exclude access to any paths starting with .git.

You can use scripted git up commands to pull from your repository. You could also make use of atomic directory moves and a scripted git-archive for more overhead, but "clean" directories that keep the backing files off your server.

share|improve this answer
I'll dig into this, thanks :) – Axiol Sep 13 '12 at 20:59

Git repository as itself cannot be used as a source for website files. You need to checkout the files from a branch to your working tree. These working tree files can then act as a web content.

The main problem here is that you can't practically checkout files from one git repository to two different working trees (that you'll then bind to your apache subdomains).

But what you can do is to have two more repositories for both of your subdomains. You can then use git hooks in your main repository to post commits to both of the "deployment repos" and then checkout the files in them from different branches.

You can find examples and a nice graph visualizing a similar setup at

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.