Git Hook under Windows

I have the following code to checkout in a working directory in the hook post-receive:

git --work-tree=d:/websites/__gitweb --git-dir=d:/_gitrepo.git/ checkout -f

Unfortunately it doesn’t seem to work. However, the command does work when I enter just this in the windows command line (cms):

git --work-tree=d:/websites/__gitweb --git-dir=d:/_gitrepo.git/ checkout -f

I have checked the permissions and the executing attributes but nothing.


I think I’m getting closer. Now I know what the problem is but I don’t know why is this happening. The hook is actually being triggered but I receive this message:

remote: Starting copy from repository to work tree...
remote: fatal: Not a git repository: 'd:/_gitrepo.git/'
remote: Finished.

I have tried to change the path of d: to the whole network path but it still doesn’t work. If I go to the remote repository and I do a git log, the changes are there and if I run the hook with sh, it works.
Why is it saying that it is not a git repository when clearly it is?

  • Git: Add directory from different location
  • How to backup local git changes for domain users?
  • Git-Windows-git-pull cannot be used without a working tree
  • git gc / git gui: Unlink of file <internal pack file name> failed
  • How to create a md file under windows
  • Embedding SVN Revision number at compile time in a Windows app
  • Python script not deleting Git files in Windows
  • How to alias in git delete merged branches
  • 2 Solutions collect form web for “Git Hook under Windows”

    I finally got it working!
    This is really weird. I had to type a pwd to see where actually is the batch being located and it showed the hook location on the server. However, in the next line I added a hostname and it showed me my local hostname.
    Then I add the whole path just like:

    echo "Starting copy from repository to work tree..."
    git --work-tree=//remotehost/d$/Webseiten/__gitweb --git-dir=//remotehost/d$/_gitr
    epo.git checkout -f
    echo "Finished."

    I hope this solution works for someone

    For a shell script (and those hook scripts will be executed as shell, even in Windows, through the msys layer of msysgit), you could use a different sort of path:

    git --work-tree=/d/websites/__gitweb --git-dir=/d/_gitrepo.git/ checkout -f

    See also other possibilities with “Posix path conversion in MinGW”

    Git Baby is a git and github fan, let's start git clone.