Git repo, where each submodule is a branch of the same repo. How to avoid double / triple ... download using Git clone --recursive?

Suppose I have the following project tree:

src
data
doc

I would like to keep all the folders in the Git repository published to Gitlab. But I do not want to track dataand docalong with src.

Therefore, I use the following strategy:

git remote add origin ADDRESS
git submodule add -b data ADDRESS data
git submodule add -b doc ADDRESS doc

It actually works fine except when I try to replicate a repository using

git clone --recursive ADDRESS

all objects are transmitted 3 times: both root dataand docall contain:

  • Origin / master
  • Origin / data
  • Origin / document

Is there an easy way to avoid this? Just to clarify what I would like:

  • - origin/master,
  • origin/data.
  • doc- origin/doc.

, , .

UPDATE

git worktree from , .

( 4- ):

git clone --recursive git@foo:foo/bar.git

:

git clone git@foo:foo/bar.git
cd bar
git worktree add data origin/data
git worktree add src/notebooks origin/notebooks
git worktree add doc origin/doc
git worktree add reports origin/reports

, .gitmodules :

[submodule "data"]
    path = data
    url = git@foo:foo/bar.git
    branch = data
[submodule "src/notebooks"]
    path = src/notebooks
    url = git@foo:foo/bar.git
    branch = notebooks
[submodule "doc"]
    path = doc
    url = git@foo:foo/bar.git
    branch = doc
[submodule "reports"]
    path = reports
    url = git@foo:foo/bar.git
    branch = reports

, Git script , ?

+4
1

Git , , . , , git worktree:

, , , src src, ,

git worktree add ../data data
git worktree add ../doc doc

fooobar.com/questions/1020/..., . git worktree, git-new-workdir script

git-new-workdir project-dir new-workdir branch

Git?

+1

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


All Articles