Git branch and subdomain

apache-2.2gitsubdomain

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 :

  • mywebsite.com would use the master branch

  • dev.mywebsite.com would use another one

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

Best Answer

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.

Related Topic