What I'm trying to accomplish
Using Git, I'm attempting to develop a setup so that I can deploy changes to my production server using a bare repository placed on the production server.
My set up is as follows:
- Local Repository with remote
production
that points to a bare repository on the production server. (e.g.git@productionserver.com:/opt/git/caf.git
) - Created bare repository on the production machine as
git
user viagit --bare init
in the above directory.
I created a post-receive hook script that (complete copy of the script is in the link below, but omitting because I believe this is the relevant portion.):
GIT_WORK_TREE="$DEPLOYDIR" git checkout -f
, where $DEPLOYDIR
points to the production copy of the repo.
Once everything was set up, I ran git push production +master:refs/heads/master
from my local copy to bring the bare repository up to date.
What's working
When committing changes locally and pushing my changes to the aforementioned bare repository, files are updated/deleted/modified in the production copy as I expected.
The Problem
If I go to the production copy and run git status
, the HEAD is not up to date, thereby resulting in a bunch of uncommitted untracked changes or modifications from the push. (Essentially all changes that I pushed are showing up as modifications)
I can resolve this by running git reset --hard origin master
, but this doesn't seem correct.
My Question
How can I set this up so that the production repo is also up to date without having to update it by force?
For reference, I'm following this tutorial: http://www.sitepoint.com/one-click-app-deployment-server-side-git-hooks/