Search code examples
gitwindows-7msysgitgit-post-receive

Git post-receive not working on non-bare repo


I'm trying to get a simple Git post-receive hook to work, but it doesn't seem to be running.

All I have in it is:

#!/bin/sh
git checkout -f master

Note that this is a non-bare repository (I've set denyCurrentBranch = ignore) so that I can push to it.

However, when I push to it, it doesn't seem to run the git checkout -f command. Running the same command then in the command line does as expected.

Note that this is a simple test case just using local repositories on my C drive.

I've managed to get a post-receive hook working by having a bare repo and putting git push in it. My intention is to have a bare "shared" repo which in the post-receive, then automatically pushes to the non-bare "website" repo (which then needs to automatically do a git checkout -f).

Any ideas why this isn't working for the non-bare repo? Or any tips on how to debug it?


Solution

  • It turns out that it was because the current working directory in the non-bare repo is the .git directory.

    So while I could just do this in the bare repo (because the git meta data folder is the same folder as the repo root) ...

    #!/bin/sh
    git do something
    

    In a non-bare repo, I have to do this ...

    #!/bin/sh
    GIT_WORK_TREE=.. git do something