Search code examples
gitgit-pullgentoo

git: pull specific branch, keep only the latest tree (without any history)


How can I pull a specific branch from a remote repository, checking out only the latest tree without keeping any history?

This question is specifically related to checking out Gentoo's Portage tree: I'd like to update my Portage tree, without keeping any history, minimizing the size of /usr/portage/.git.


Solution

  • Like this:

    $ git clone --branch dotnet-mono-eclass-lat --depth 1 https://anongit.gentoo.org/git/repo/gentoo.git
    

    From man git-clone:

    --branch <name>, -b <name>

    Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to <name> branch instead. In a non-bare repository, this is the branch that will be checked out.

    --depth <depth>

    Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches.