How to clone a local repo with submodules?

Say I recursively clone a repo.

$ git clone --recursive ssh://server/project/client
Cloning into 'client'...
remote: Counting objects: 191, done
remote: Finding sources: 100% (191/191)
remote: Total 191 (delta 53), reused 159 (delta 53)
Receiving objects: 100% (191/191), 27.59 KiB | 0 bytes/s, done.
Resolving deltas: 100% (53/53), done.
Checking connectivity... done.
Submodule 'gui' (ssh://server/project/client/gui.git) registered for path 'gui'
Cloning into 'gui'...
remote: Counting objects: 3213, done
remote: Finding sources: 100% (3213/3213)
remote: Total 3213 (delta 1272), reused 3107 (delta 1272)
Receiving objects: 100% (3213/3213), 47.88 MiB | 12.05 MiB/s, done.
Resolving deltas: 100% (1272/1272), done.
Checking connectivity... done.
Submodule path 'gui': checked out '7315db8d7a8b36929f7874dc5477359839ec51ce'

Now I want to create a local clone of this local repo (perhaps after making and making changes locally).

$ git clone --recursive client/ client_copy
Cloning into 'client_copy'...
done.
Submodule 'gui' (/home/deployer/client/gui.git) registered for path 'gui'
fatal: repository '/home/deployer/client/gui.git' does not exist
Clone of '/home/deployer/client/gui.git' into submodule path 'gui' failed

My .gitmodulesfile is as follows:

[submodule "gui"]
        path = gui
        url = ../client/gui.git

Why is this failing, and how can I solve the problem?

+4
source share
4 answers

There is a problem with your file .gitmodules. The submodule urlin your project is defined as the relative path from the superproject repository, but when the cloned submodules are placed using the location path.

, git url, path.

, (git clone /path/to/superproject), .gitsubmodules url ./<whatever-the-path-is>. , gui :

[submodule "gui"]
        path = gui
        url = ./gui

.gitmodules, , :

git submodule sync
git submodule update --init --recursive

!

+4

, , - gitlab (SRC - , DST - ):

git clone $SRC $DST
MODULES=$(git -C $SRC config --file .gitmodules --name-only --get-regexp url)
for MODULE in ${MODULES}; do
    MODULE_PATH=$(git -C $SRC config ${MODULE});
    git -C $DST config ${MODULE} ${MODULE_PATH};
done
git -C $DST submodule update --init --recursive;

, , ...

+1

: Git 2.12 git submodule update --init --recursive - .
Git 2.13 (Q2 2017)

. commit cf9e55f (07 2017 .) (mbrandonw).
( Junio ​​C Hamano - gitster - 5bceab4, 24 2017 )

submodule:

"git submodule" . , , :

git -C main submodule add ../sub\\with\\backslash
fatal: repository '/tmp/test/sub\witackslash' does not exist
fatal: clone of '/tmp/test/sub\witackslash' into submodule path

To solve this problem, convert calls to 'in read -r' to git-submodule.shto prevent backslash extension of submodule names.

0
source

If we want to clone submodules from locally cloned submodules, I will approach the version below. This allows you to use only one level of submodules.

git clone $src $dst
modules=$(git -C $src config --file .gitmodules --name-only --get-regexp url)
for module in $modules; do
  module_path=$(git -C $src config --file .gitmodules ${module%.url}.path)
  git -C $dst config ${module} $src/$module_path
done
git -C $dst submodule update --init

0
source

All Articles