4

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.

watain
  • 4,838
  • 4
  • 34
  • 35

2 Answers2

2

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.

Community
  • 1
  • 1
Arkadiusz Drabczyk
  • 11,227
  • 2
  • 25
  • 38
  • Thanks! Would you be able to provide the needed commands when updating an existing repository? – watain Feb 09 '16 at 08:39
  • What do you mean by `existing repository`? Did you already clone `portage` repository using a regular `git clone` command? – Arkadiusz Drabczyk Feb 09 '16 at 08:43
  • Yes, exactly. The remote repository has already been cloned to `/usr/portage`. – watain Feb 09 '16 at 08:49
  • IIUC, you already have an entire repository with all branches and history. In such case you can just create a new local branch off the remote branch with `git checkout `. – Arkadiusz Drabczyk Feb 09 '16 at 08:52
2

to download repository without history : git clone --depth 1

To update already cloned shallow repository:

git pull --depth 1 or git pull --update-shallow

SnehalK
  • 699
  • 4
  • 12