Git clone without .git directory

Justin picture Justin · Jul 16, 2012 · Viewed 107.8k times · Source

Is there a flag to pass to git when doing a clone, say don't clone the .git directory? If not, how about a flag to delete the .git directory after the clone?

Answer

Adam Dymitruk picture Adam Dymitruk · Jul 16, 2012

Use

git clone --depth=1 --branch=master git://someserver/somerepo dirformynewrepo
rm -rf ./dirformynewrepo/.git
  • The depth option will make sure to copy the least bit of history possible to get that repo.
  • The branch option is optional and if not specified would get master.
  • The second line will make your directory dirformynewrepo not a Git repository any more.
  • If you're doing recursive submodule clone, the depth and branch parameter don't apply to the submodules.