getting "fatal: not a git repository: '.'" when using post-update hook to execute 'git pull' on another repo

GitGithooks

Git Problem Overview


I'm new to git so I apologize (and please correct me) if I misuse terminology here, but I'll do my best.

I'm trying to set up a bare git repo (hub) and a development site working copy (prime) on a web server. I've tried to pattern it after http://joemaller.com/990/a-web-focused-git-workflow/">this article. I want the development working copy to be updated whenever the hub repo is pushed to. I'm under the impression that the proper hook for this is post-update, which I have created like so:

#!/bin/sh
whoami
cd /path/to/working-copy/
RET=`git pull`
echo $RET

Update

When I push changes from my local repo to the bare hub I get the following output from the post-update script:

remote: sites
remote: fatal: Not a git repository: '.'

However if I SSH into the server as user 'sites' and execute this script manually it works great Any ideas as to what might be going wrong with this hook or script?

Git Solutions


Solution 1 - Git

Here is the script that ultimately worked. I think the bit I was originally missing that prevented it from working remotely was the unset GIT_DIR

#!/bin/sh
cd /path/to/working-copy/ || exit
unset GIT_DIR
git pull repo branch

exec git-update-server-info

Solution 2 - Git

Try instead:

#!/bin/sh
cd /path/to/working-copy/
env -i git pull

Solution 3 - Git

Despite that unset GIT_DIR just works.

the problem occurs when you set GIT_DIR wrongly somewhere else.

you can just add that instead: GIT_DIR=.git/ It will work

Solution 4 - Git

In my case I had specified a working tree, and this breaks on some commands, like pull (or more precisely fetch).

To unset the working tree if it is in your git config is via:

git config --unset core.worktree

(There are other ways to set a work tree)

Important to note,

There is next to no change of this being your problem unless you yourself dug this hole around you by using a custom worktree in the first place.

Banter:

This implies to me that git internals use paths relative to the worktree + .git/ in some cases. In my experience worktrees are not well supported whatsoever, except by the most fundamental parts of git. I have not experimented thoroughly, Git would probably behave if I set whatever the git directory config variable is properly, which I have not played with.

Solution 5 - Git

You probably have a permissions issue. I'm not sure how you have setup your bare git repo, but if it's running under the git user, make sure that git user is allowed to perform the git pull in your project directory.

Optionally try this to find out what user you are when the hook is run:

echo `whoami`

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTy WView Question on Stackoverflow
Solution 1 - GitTy WView Answer on Stackoverflow
Solution 2 - GitGeraldo Luis da Silva RibeiroView Answer on Stackoverflow
Solution 3 - GitZvika NavehView Answer on Stackoverflow
Solution 4 - GitThorSummonerView Answer on Stackoverflow
Solution 5 - GitAriejanView Answer on Stackoverflow