Select only a subset of folders when using Git clone

Is there a way to clone only a subset of the source branch in git?

eg.

I have the following folder structure:

a
| _ B
| _ C
| _ D

And after the clone I want to have:

a
| _ C
| _ D

I want to use this thread to deploy my application:

  • To make the clone faster, taking only part of the repo and ignoring unnecessary development files.
  • I do not want some files to be produced due to security concerns.

Any tips?

+4
source share
2 answers

As follows from the comment, you cannot clone part of the path. If you are used to various version control paradigms, such as the one used by subversion, this may seem unintuitive at first. The reason you cannot do this is because git stores snapshots of the whole tree. This way you can get a small clone, keeping in mind that you only get recent history to a certain extent. It looks more like a horizontal slice or slice, rather than the vertical one you are after.

The best way to get what you want is to use submodules. If you already have everything in one repository, you will either have to start a new job with this paradigm, or split the repository into several repositories using the filter branch. It would also be difficult, since you would end up with empty commits in all repositories, and if you got rid of them, you would have a difficult continuation of the filter branch to associate the correct commits in the submodule with the parent repository.

Take a look at the chapter on submodules at http://git-scm.com/book .

+5
source

What you want is possible with Git 1.7 with so-called sparse validation.

A good explanation is found here .

+2
source

Source: https://habr.com/ru/post/1445966/


All Articles