8

I try to clone my local git repository inside the pre-push script (client hook). I get the exception:

fatal: working tree '...' already exists.

I don't understand the exception, since i obviously clone the repo to a different directory.

Any ideas?


I tried that:

unset GIT_DIR
cd ..
git clone ./TestTest/ /tmp/PrePushTestClone

It fails exactly the same way :(

user1879408
  • 1,948
  • 3
  • 17
  • 27

3 Answers3

12

I had the same issue, except I was dealing with pre-commit hook. When trying to clone another repo inside the current repository there's an error with text something like:

fatal: working tree '.' already exists.

To fix this issue I had to add this line before clone:

unset GIT_WORK_TREE

I have found this solution here: https://github.com/bower/bower/issues/1033

sobolevn
  • 16,714
  • 6
  • 62
  • 60
3

Happened to me too. I realized that I ran git clone in a bash session opened from git rebase -i that had GIT_DIR and GIT_WORK_TREE set in the environment. Exiting the bash session resolved the issue...

  • Thanks for pointing me in the right direction. I was opening a terminal from within git gui in my case (by a tool command) with all Git specific env vars set for that repository. – MattSchmatt Nov 14 '20 at 16:00
1

since i obviously clone the repo to a different directory.

Your hook might consider $GIT_DIR as referencing your current repo, which will interfere with a git clone.

Make sure to:

  • unset GIT_DIR in your pre-push script
  • git clone in a folder outside your current repo folder
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250