Is it possible to do a partial clone/branch with either bazaar, mercurial or git? Is it possible to do a partial clone/branch with either bazaar, mercurial or git? git git

Is it possible to do a partial clone/branch with either bazaar, mercurial or git?


Cloning a subset of the tree is not possible, as far as I know, but there are other possibilities.

Git: The command git clone has a --depth flag:

--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.

Bazaar: The flag --lightweight for the checkout command only downloads a working directory instead of the whole history and saves bandwidth and disk space. All operations are still supported, but a network connection is required to perform them.

I do not know whether Merurial has this feature or not.


If you already have a repository and you'd like to do this, it's going to be a pain.

If you're going to be doing this with brand new repositories, you might want to look at Mercurial's new subrepos.

Basically you create standalone repositories for certain directories:

myproject/    .hg/    source code/        ... files here ...    documentation/ (subrepo)        .hg/        ... files here ...    graphics/ (subrepo)        .hg/        ... files here ...

This isolates the different pieces of the project in different repositories. The "containing" repo (myproject in this case) keeps track of what revision the subrepos are at every time you commit. The subrepo wiki page I mentioned explains it well.


Judging from this wiki page, this feature is not yet implemented in Mercurial, however there is an extension that can do approximately what you want by 'converting' a repository or its part, rather than actual branching. Since it can convert from and to Hg, it may work as partial cloning. Is this what you needed?