2

I want to set up Git so I can have various versions of the same website accessible simultaneously. For example, a 'Sandbox' site, a 'Staging' site and a 'Production' site.

I currently have Git 1.7.11 installed on Windows, and Git running on my CentOs 5.5 VPS. Locally I have 2 branches, 'master' and 'dev'. Remotely I have 2 branches, 'master' and 'dev'.

I have followed the following tutorial showing how to manage a website using Git, but now feel I'm being rather stupid. I can commit files to either the dev branch or master branch from my local machine to the remote one, and these are checked out using a post-update hook into my Apache 'htdocs' directory. This works great, and as I switch branches the file 'changes'.

However, I want to have both versions accessible at the same time so I can run a site whilst a client can review a staging version of the same site. How do I do this? Afterward I plan to use Git to merge staging / dev into master.

Is this the best way? Checkouts in the post-update hook?

GIT_WORK_TREE=/htdocs/production git checkout master -f
GIT_WORK_TREE=/htdocs/staging git checkout dev -f
codinghands
  • 1,741
  • 2
  • 18
  • 31

2 Answers2

0

Checkouts in the post-update hook will work, but you might want to define also GIT_DIR

See:

That will make sure the git commands knows where the git repo is.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

This may not help your question regarding Git, but I would not prefer this kind of workflow in web development, when there is a way which is, in my opinion, something that requires a little more work, but in exchange is a lot more flexible and reliable.

I would just mark a bare, public repository where all commits go by push and fetch (like what you are using that has the hooks), but without any hooks. I would then have 2 project directories on the remote server: one for dev and one for master; both using cloned, non-bare git repositories (each having a .git folder). So you would have 1 bare repository on your web server (or it can be on any server) and 2 non-bare repositories.

In this case, you can push all you want locally, the working directory in your web project directories will only change when you decide to pull. This has the added benefit to being able to make quick changes directly on the remote server's project directory in case an error relating to the environment of the project comes out, which you can commit the fix and push it back easily.

And with multiple remote project directories (and urls), you can have multiple project states simultaneously on the same server.

Attila Szeremi
  • 5,235
  • 5
  • 40
  • 64