I am writing a git post-receive hook that will clone a separate repo as part of a deployment. It clones the repo to a certain folder and uses the `-C` option in subsequent git commands to set the directory to that of the checked out repo (as documented in the [man page](https://www.kernel.org/pub/software/scm/git/docs/git.html)).

The hook works as expected when run manually from the command line, however when the hook is run by git (ie when a push is received) the command fails with `fatal: Not a git repository: '.'`. When I swap out the `-C` for a `--git-dir` it works.

This is fairly simple to reproduce, create a bare repo `git init --bare` and make an executable hook with the contents:

```
#!/bin/bash
set -xe

SOME_REPO_URL=???? # Some repo that is not this one
repopath=/tmp/somerepo

git clone $SOME_REPO_URL $repopath

# 1: This fails when run through the git hook
git -C $repopath checkout -b somebranch HEAD~1

# 2: This works every time
# git --git-dir $repopath/.git checkout -b somebranch HEAD~1

```

Running the script from the command line will work as expected, but when you push to the repo the hook will fail. Commenting `1` and uncommenting `2` will work in both cases.

I can't find any documentation that would indicate that this is intended behaviour - an explanation would be appreciated.

This is git 2.7.4 on Ubuntu 16.04.