10

Is there a way to fork a file from a foreign Git repository without cloning the whole repository?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alexander Zeitler
  • 11,919
  • 11
  • 81
  • 124
  • You need to clone, but then you can strip out all you don't want. – Thilo Dec 09 '11 at 08:22
  • This is very close to http://stackoverflow.com/questions/6680709/create-new-git-repo-from-already-existing-repos-subdirectory – Thilo Dec 09 '11 at 08:23

2 Answers2

6

The closest you could get to doing this is by using sparse checkout, which means using Git 1.7+ and you still need to clone the repo (or use clone's --depth option to do a shallow clone). Borrowing largely from this answer, you could do the following:

git clone --no-checkout <URL to git repo> myrepo
cd myrepo
git config core.sparseCheckout true
vim .git/info/sparse-checkout # Add files you want checked out
git checkout <branch you want>

If you have Git version 1.7.7-rc0 or later, you can set configuration options with the clone command:

git clone --config core.sparseCheckout=true --no-checkout <URL to git repo> myrepo

Also, see the following:

Community
  • 1
  • 1
Go Dan
  • 15,194
  • 6
  • 41
  • 65
  • thx, but somehow the first line results in "error: unknown option `config'" – Alexander Zeitler Dec 12 '11 at 11:49
  • The `clone` `--config` option is available beginning with Git 1.7.7-rc0. If you have a prior version, remove the `--config core.sparseCheckout=true` and after the `git clone` command, execute `git config core.sparseCheckout true`. But you will still need a version at least 1.7.0. – Go Dan Dec 12 '11 at 13:48
-3

Unlike Subversion, Git does not support partial checkouts.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rgngl
  • 5,353
  • 3
  • 30
  • 34