Is there a way to fork a file from a foreign Git repository without cloning the whole repository?
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 myrepo
cd myrepo
git config core.sparseCheckout true
vim .git/info/sparse-checkout # Add files you want checked out
git checkout
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 myrepo
Also, see the following: