For my website I have a bare repository (where I push to) and a clone with working directory which serves as document root.
In the bare repository I've setup a post-receive
hook to auto-update the website:
#!/bin/sh
WEB_DIR=/var/www/www.mysite.com
# remove any untracked files and directories
git --work-tree=${WEB_DIR} clean -fd
# force checkout of the latest deploy
git --work-tree=${WEB_DIR} checkout --force
Unfortunately, after a push to the bare repository the changes do show up in the documentroot, but as but they show as unstaged changes.
I then have to clean everything up by doing a git checkout -- <files>
followed by a git pull
.
Obviously the idea is that this works out of the box, if I have to do the cleanup+pull manually I might as well remove the post-receive
hook.
I read it's better to use checkout in the post receive than a pull in various locations so I don't know if that would be a good change...
I'm not a git expert so I'm hoping someone can tell me what I'm missing? The solution does seem to work for a lot of people as I've found it in several tutorials out there.