1

I have two non-bare git repositories, one a local machine in which I develop and the second on a server, on which I build. In the local repository I have a post-commit hook with "git push -f server". Each time I commit on a local machine, changes are pushed to the server. Unfortunately, on the remote git stages a "revert" of my changes. I have to do a "git reset HEAD --hard" on the server manually, which is quite annoying. How can I tell git to accept changes without staging a revert or how can I automatically do a reset on the server? I have tried to add a post-receive hook on the server, but it doesn't work.

I have found a similar question How do I push to the current git branch on remote, and have changes reflected immediately? , but it did not help (

Community
  • 1
  • 1
Yuriy Kulikov
  • 1,695
  • 1
  • 12
  • 26

1 Answers1

0

You have the choice of:

    $ cat > hooks/post-receive
    #!/bin/sh
    GIT_WORK_TREE=/var/www/www.example.org git checkout -f
    $ chmod +x hooks/post-receive
  • or, you could push to a bare repo, and have an hook switching to the live non-bare repo, pulling the new commits from the bare repo:
    See "Git submodule on remote bare" (you can ignore the submodule aspect)

I tend to favor the second approach, which seems "cleaner" than directly changing HEAD on a non-bare repo.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Thanks, VonC. Unfortunately post-receive hook on the server is very slow, because it seems to be executed on a local machine, which means files are accessed over the network. Project is quite huge and reset takes a couple of minutes. "git config receive.denyCurrentBranch warn" does not make any difference. – Yuriy Kulikov Apr 10 '12 at 14:20
  • @YuriyKulikov that shouldn't be the case for a post-receive set on a bare repo, because said bare repo is just on the same box than the live non-bare repo. No network invoved. – VonC Apr 10 '12 at 14:29