Last Updated: May 02, 2019
·
8.625K
· mxcl

Faster Git Clones

If you don’t need the Git history when cloning (which is often the case if you are just forking to make a pull request) then you can save clone time thus:

git clone --depth 1 https://github.com/CocoaPods/Specs

For repositories with large histories, this can be a significant saving, and you are being kind to GitHub’s resources.

9 Responses
Add your response

Nice! Thanks for sharing!

over 1 year ago ·

Thats a sweet tip

over 1 year ago ·

Awesome! Do you know if the same can be applied when adding a submodule?

over 1 year ago ·

Good tip, but it must be complete. Nothing comes without price, and in this case (from the man page):

  • ... you cannot clone or fetch from it, nor push from nor into it
  • is adequate if ... want to send in fixes as patches

The second line means -- no pull requests from a "shallow" clone repo.

over 1 year ago ·

I've pushed from such clones many times and made pull requests from such repos. The manpage doesn't seem accurate.

Cloning from and fetching from clones is something I rarely need, and in those cases you can fetch into a separate remote and hard reset if necessary.

over 1 year ago ·

I read the documentation a few months ago when I saw the flag somewhere and I assumed it was accurate too. I just cloned one of my repos with the flag and I was able to push and pull. Looks like the manpage needs to be updated.

over 1 year ago ·

It causes a lot of problems, I speak from experience.

over 1 year ago ·

Note that this only works with git 1.9 and up, see http://stackoverflow.com/questions/6941889/is-git-clone-depth-1-shallow-clone-more-useful-than-it-makes-out

The manpage has been corrected in recent git versions, as referenced on in the question linked above.

over 1 year ago ·

I assure you I have been using this since Git 1.4 or so.

over 1 year ago ·