Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 843
user1879408 Avatar asked Dec 11 '15 13:12

user1879408


3 Answers

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

like image 157
sobolevn Avatar answered Nov 09 '22 02:11

sobolevn


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

like image 44
Benny Halevy Avatar answered Nov 09 '22 03:11

Benny Halevy


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
like image 1
VonC Avatar answered Nov 09 '22 03:11

VonC