user1879408
user1879408

Reputation: 2028

Exception "working tree already exists" while cloning GIT repo in pre-push hook

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 :(

Upvotes: 9

Views: 8359

Answers (3)

Benny Halevy
Benny Halevy

Reputation: 41

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...

Upvotes: 4

sobolevn
sobolevn

Reputation: 18080

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

Upvotes: 13

VonC
VonC

Reputation: 1325357

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

Upvotes: 1

Related Questions