2

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?

Community
  • 1
  • 1
Jodes
  • 14,118
  • 26
  • 97
  • 156
  • 1
    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. – ckruczek Aug 12 '15 at 12:11
  • possible duplicate of [Do a "git export" (like "svn export")?](http://stackoverflow.com/questions/160608/do-a-git-export-like-svn-export) – Jodes Aug 13 '15 at 08:21
  • Never seen a git repository without the `.git` directory. Not possible. Probably just hidden in your case. – Rohan Aug 07 '20 at 12:04

3 Answers3

5

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
toydarian
  • 4,246
  • 5
  • 23
  • 35
  • 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). – user4301448 Aug 03 '23 at 17:32
  • 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](https://stackoverflow.com/a/76296193/3683639). – toydarian Aug 09 '23 at 10:56
2

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)

manojlds
  • 290,304
  • 63
  • 469
  • 417
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.

Dustin
  • 2,064
  • 1
  • 16
  • 12