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

Asked

Viewed 1,769 times

8

I 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, download the repository without previous changes of other commits.

How can I do that?

1 answer

11


Use the switch --depth:

Example:

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

Note however that 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 not usually a problem)
  • Clone operations from remote repositories may take a while, but they are not common (I usually clone a remote repository 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 to, 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

  • Well completes the answer!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.