Set up a remote Git repositiory to automatically checkout to a working tree after a git push command. Useful for the auto deployment of web site files on a web server.
Create a bare GIT repository:
mkdir project.git && cd project.git git init --bare
Create a detached work tree:
mkdir /home/user/myproject git config core.worktree /home/user/myproject git config core.bare false git config receive.denycurrentbranch ignore
Example hooks/post-receive script:
#!/bin/sh git checkout -f
Now when you push to your remote repository, the post-receive script will run a checkout of the latest files to you working tree.
3 Comments
works like a charm. thanks!
Thanks for this, works a treat and its been a real lifesaver.
A quick note: I just spent 20 minutes cussing at my terminal window trying to figure out why, when I ran these commands yesterday as an experiment, they worked fine. Today I ran them and after I set core.bare to false I received:
fatal: core.bare and core.worktree do not make senseAs it turns out, today I’d tried to run the commands in the order above, whereas yesterday, I set core.bare first before I set core.worktree. Running the commands in that order gave the desired result. This was in Git 1.7.5
When I try to push, I’m getting this error:
fatal: You are on a branch yet to be born
I’m on git 1.7.6 and I’m using the steps above to try to deploy after a push. Any thoughts?
One Trackback
[...] http://www.deanoj.co.uk/programming/git/using-git-and-a-post-receive-hook-script-for-auto-deployment... [...]