Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fork a file from a Git repository without cloning the repository

Tags:

git

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

like image 811
Alexander Zeitler Avatar asked Dec 09 '11 08:12

Alexander Zeitler


1 Answers

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:

  • Partial clone with Git and Mercurial
  • How to retrieve a single file from specific revision in Git?
  • Sparse checkout in Git 1.7.0?
  • Is it possible to do a sparse checkout without checking out the whole repository first?
like image 104
Dan Cruz Avatar answered Sep 20 '22 11:09

Dan Cruz