0

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 via git --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/

Phil Birnie
  • 1,104
  • 2
  • 12
  • 29
  • So, is this a correct claim/rephrase, and if so, does it make the problem clearer? Claim: your production server has a git repository it doesn't use (`$DEPLOYDIR/.git`), a bare repository that it does use (`/opt/git/caf.git`), and a work-tree that it does use (`$DEPLOYDIR`)? – torek Dec 10 '13 at 23:24
  • @torek - I feel like an idiot. So with this setup the `$DEPLOYDIR` _shouldn't_ have a git repository - is that correct? To date, I'd been logging into the server and fetch/merging; obviously this is an attempt to replace that. – Phil Birnie Dec 10 '13 at 23:47
  • 1
    Yes, this kind of auto-deploy setup means the place you `checkout` to is just a directory, with no underlying repository. Which, added on top of a bare repository, equals: a regular repo with regular work dir, but split-up to accomodate git's pickiness. :-) – torek Dec 10 '13 at 23:50

0 Answers0