Juan Simón
Juan Simón

Reputation: 309

Is possible clone only a folder from remote repository?

I want download only 2 folders from remote git repository. In this case is the ubuntu kernel git repository.
Download all kernel is a waste of time and bandwidth if I only want 2 folders.
Is there any way to do this with git?

Upvotes: 1

Views: 986

Answers (3)

Kjuly
Kjuly

Reputation: 35181

It seems Git CANNOT implement this.

I thought "Sparse Checkout" will works, but as @ HolgerJust said:

This will still download the full remote repository. It just doesn't checkout all the files into the working copy, but they are still available in the local index.

He's right.


Yes, you can. You can use Sparse Checkout.

Here's a simple example:

$ mkdir destinationFolder
$ cd destinationFolder
$ git init
$ git remote add origin [email protected]:Kjuly/iPokeMon.git
$ git config core.sparseCheckout true
$ echo 'Pokemon/Models/*' > .git/info/sparse-checkout
... echo more if you need
$ git pull origin dev

And finally, you'll get files:

destinationFolder
- Pokemon
- - Models

Upvotes: 1

forvaidya
forvaidya

Reputation: 3315

No you can't create a partial clone

Upvotes: 1

Nevik Rehnel
Nevik Rehnel

Reputation: 52015

No, not in the way you're asking. But you can do one of these:

  1. download a tarball -- the repository's web-ui should offer such an option, otherwise you can use git archive (man page, google and SO will help you with its usage); or
  2. do a shallow clone, using the --depth switch; this will download only the given number of commits, so you don't get the whole history. The git clone manpage has more details about it.

Upvotes: 2

Related Questions