Is there a way to fork a file from a foreign Git repository without cloning the whole repository?
Unlike Subversion, Git does not support partial checkouts.
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: