3

There are at least 3 previous questions explaining how to clone a repository without the .git directory:

From those questions, it seems you can't just run git clone and have the repository cloned without the .git directory.

Yet, in the majority of repos I've cloned, such as the one in the command below, no .git directory is made.

git clone https://github.com/scotch-io/scotch-box.git

What determines whether a straight forward git clone command creates a .git directory or not?

3
  • 2
    Well after I cloned the repo given by you, I have a .git directory. So the only situation I can imagine where you don't have a .git directory is a bare repository. But even if you clone this bare repo git will create a .git folder. It is mandatory for git to work properly. Commented Aug 12, 2015 at 12:11
  • possible duplicate of Do a "git export" (like "svn export")? Commented Aug 13, 2015 at 8:21
  • 1
    Never seen a git repository without the .git directory. Not possible. Probably just hidden in your case. Commented Aug 7, 2020 at 12:04

3 Answers 3

6

There is always a .git directory after a git clone. No exception. If you don't see it then it is hidden (How this happens depends on your operating system. ls on linux does not show files/dirs that start with a dot. You would have to use ls -a.)

The .git directory is essential as it contains all files and info used by git.

Here is what happens after the git-clone you mentioned:

/tmp % git clone https://github.com/scotch-io/scotch-box.git
Cloning into 'scotch-box'...
remote: Counting objects: 83, done.
remote: Total 83 (delta 0), reused 0 (delta 0), pack-reused 83
Unpacking objects: 100% (83/83), done.
Checking connectivity... done.
/tmp % cd scotch-box 
/tmp/scotch-box (git)-[master] % la
total 40K
drwxr-xr-x 4 t t 4.0K 12. Aug 14:10 .
drwxrwxrwt 8 root  root   12K 12. Aug 14:10 ..
drwxr-xr-x 7 t t 4.0K 12. Aug 14:10 .git
-rw-r--r-- 1 t t   18 12. Aug 14:10 .gitignore
-rw-r--r-- 1 t t 7.4K 12. Aug 14:10 README.md
-rw-r--r-- 1 t t  480 12. Aug 14:10 Vagrantfile
drwxr-xr-x 2 t t 4.0K 12. Aug 14:10 public
Sign up to request clarification or add additional context in comments.

3 Comments

You say 'no exception' but I've just seen git clone on WSL clone a repo successfully, but then the .git directory is missing. I've been using *nix and git for decades and never seen anything like it, and it's not some stupid mistake on my part (like not cd-ing into the directory).
The .git directory is essential for git to work. If you are using "default" git and don't git clone --bare, you will get a .git directory. If you don't have this directory and git works, you are not looking in the right place. If you clone, don't have this directory and git doesn't work, you have discovered a bug.
"but I've just seen git clone on WSL clone a repo successfully, but then the .git directory is missing." Nested repos? Look at parent folder for .git?
3

Are you sure you are looking for .git in the right location? When you do a clone like git clone https://github.com/scotch-io/scotch-box.git, the repo is actually clone in a directory scotch-box and hence .git will be at scotch-box/.git

On the other hand, doing:

git clone https://github.com/scotch-io/scotch-box.git .

note the . at the end - will clone in current folder (if that is not already a git repo)

Comments

0

I had the same issue. I'm not sure if it was a corrupt install or a bug in the version of git I was using (1:2.34.1-1ubuntu1.6). My environment was Windows Linux Subsystem (WSL), Ubuntu 22.04.2 LTS. I was cloning libjpeg-turbo and not getting a .git folder! The issue was repeatable.

I simply updated my version of git (1:2.34.1-1ubuntu1.9) and the problem was gone.

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.