How to clone / download a repository with only the last commit?

8

I have read a while ago that it is possible to clone a repository in a more performative way just by downloading the last commit, that is, downloading the repository without previous changes to other commits.

How can I do this?

    
asked by anonymous 09.01.2015 / 16:46

1 answer

11

Use the switch --depth :

Example:

git clone --depth=1 <url_do_meu_repositório>

However, this practice of shallow copy (SVN style) is not usually the best solution in the Git world for a number of reasons:

  • The history of a repository is heavily compressed (disk space is often not a problem)
  • Clone operations from remote repositories can take a while, but they are not usually mundane (I usually clone a remote repository only once, if I need more clones, I make local clones).
  • Git also has tools like filter-branch and purge to decrease the size of very large repositories.
  • Alternatively, if you really need it, you can clone a single branch:

    git clone -b meugalho --single-branch <url_do_meu_repositório>
    

Source: SOen - Using git to get just the latest revision

    
09.01.2015 / 16:50