Tell me, is it possible to clone in git not the whole project of the master branch, but only 1 directory from this branch? And to continue to work with her?
- 3No This is impossible by definition. - abalckin
- onestackoverflow.com/a/13738951/2908793 there the first answer explains why this is fundamentally wrong. - etki
- @Etki: the link points to another answer that explains how to do sparse checkout , that is, it allows only a given set of paths in the working directory to have (including one directory). - jfs
- @jfs I link to it and threw it. - etki
1 answer
As far as I know, the entire master will have to be downloaded anyway. But it is possible that not all files are "unpacked".
git init имяреп cd имяреп git remote add origin ссылка git fetch At this point, the master (and all other branches) will be downloaded, but not unpacked.
Now turn on the special mode:
git config core.sparseCheckout true We indicate which files we want
echo вот/этот/каталог >> .git/info/sparse-checkout And unpack the files:
git checkout origin/master -B master As a result, вот/этот/каталог/файл.txt will fall into the working directory, and не/тот/каталог/файл.txt not.
If there are many branches in the repository and you need to save traffic, you can download not all (for example, after git remote add change the .git/config file so that it does not fetch = +refs/heads/*:refs/remotes/origin/* , but fetch = +refs/heads/master:refs/remotes/origin/master ), and also download not the whole story ( git fetch --depth=50 ).