6

When I git clone from a repo, I get,

fatal: Could not get current working directory: No such file or directory

What do I do? I have checked the server and found that .git file exists. The server is running a Gitlab instance. I have configured ssh properly with the keys, and I've been committing & cloning for a while now without any error, and this happens all of a sudden.

FWIW, I'm doing the git clone in a bash script.


Update

This is my bash script,

for repo in $repos
do
   git clone $repo /tmp/tmpdir/
   # do stuff with /tmp/tmpdir/
   rm -rf /tmp/tmpdir/
done

for the first repo it's fine, but when the for gets into the second repo it fails and gives the above fatal error.

6
  • Does the bash script delete any directories? It sounds like you've deleted the working directory. Commented Aug 5, 2014 at 12:01
  • 1
    Working directory is wherever the script is run from, unless that script changes directory. How are you calling the script? Commented Aug 5, 2014 at 12:05
  • 1
    Presumably somewhere in your do stuff you cd into /tmp/tmpdir/? If so, add cd /tmp/ before your rm line. Commented Aug 5, 2014 at 12:21
  • @DaveMorrissey Ridiculously awesome! I can't believe I was missing this. Commented Aug 5, 2014 at 12:24
  • I'll add that as an answer. Commented Aug 5, 2014 at 12:25

2 Answers 2

4

My guess is that somewhere in your do stuff section you change directory into /tmp/tmpdir/ so that in the next loop, the current working directory no longer exists. The fix is to change directory to /tmp/ (or anywhere really) before removing the /tmp/tmdir/ directory.

Sign up to request clarification or add additional context in comments.

Comments

1

In my case, this was caused by issuing a "git clone" from a subdirectory of an already existing git repo. I had to cd outside of the existing repo before I could clone the new repo.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.