Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does git clone sometimes create a .git directory, and sometimes not?

Tags:

git

git-clone

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

  • Do a "git export" (like "svn export")?
  • Git clone without .git directory
  • What's the best practice to "git clone" into an existing folder?

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?

like image 601
CL22 Avatar asked Dec 02 '25 05:12

CL22


1 Answers

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
like image 59
toydarian Avatar answered Dec 03 '25 18:12

toydarian