tags:

views:

56

answers:

2

I've got a 2 web servers, one testing and one live. Both have their codebases managed with git.

I develop on the testing server, then push the changes from a master branch on the testing server to the live server with git push. However, at the moment I then have to log in to the live server and run git reset --hard for the changes to be reflected in the live code.

The warning message git displays when I push suggests changing the setting of receive.denyCurrentBranch to change how this push is handled. However, as I understand, I can either have it refuse the push, accept it with a warning and require a git reset, or accept it with no warning and require a git reset. Can I have it accept the push an not require the reset?

Thanks!

+5  A: 

It sounds like you're pushing into a non-bare repo (that is, one that has a copy of the repo's files checked out on-disk). You can push into it, but Git won't automatically update the working-copy files without a git reset (or git checkout). You could use a post-receive hook to do the checking out automatically, though -- there's a good how-to available here.

mipadi
Creating the post-recieve hook works really well, thanks!
marxjohnson
A: 

mipadi is right that you really need to have a bare repo to pull from on your production server. If you're not comfortable with a post-commit hook (lots of people aren't). You can create a cron job on that server that runs git pull origin master every half hour or so.

Bryce
A cron job wouldn't quite solve my problem - I still only want changes to be pushed to the live server on my explicit command.Perhaps having `git reset --hard` running on a cron job would work, but the hook seems like a more elegant solution.
marxjohnson
yeah, for sure, a hook is the best way to go. Some people are intimidated by writing them so I wanted to show an alternative for good of the order
Bryce