How to “git clone” including submodules?

后端 未结 15 839
夕颜
夕颜 2020-11-22 05:40

I\'m trying to put a submodule into a repo. The problem is that when I clone the parent repo, the submodule folder is entirely empty.

Is there any way to make it so

相关标签:
15条回答
  • 2020-11-22 06:05

    You can use the --recursive flag when cloning a repository. This parameter forces git to clone all defined submodules in the repository.

    git clone --recursive git@repo.org:your_repo.git
    

    After cloning, sometimes submodules branches may be changed, so run this command after it:

    git submodule foreach "git checkout master"
    
    0 讨论(0)
  • 2020-11-22 06:10

    I think you can go with 3 steps:

    git clone
    git submodule init
    git submodule update
    
    0 讨论(0)
  • 2020-11-22 06:10

    I had the same problem for a GitHub repository. My account was missing SSH Key. The process is

    1. Generate SSH Key
    2. Adding a new SSH key to your GitHub account

    Then, you can clone the repository with submodules (git clone --recursive YOUR-GIT-REPO-URL)

    or

    Run git submodule init and git submodule update to fetch submodules in already cloned repository.

    0 讨论(0)
  • 2020-11-22 06:11

    With version 2.13 of Git and later, --recurse-submodules can be used instead of --recursive:

    git clone --recurse-submodules -j8 git://github.com/foo/bar.git
    cd bar
    

    Editor’s note: -j8 is an optional performance optimization that became available in version 2.8, and fetches up to 8 submodules at a time in parallel — see man git-clone.

    With version 1.9 of Git up until version 2.12 (-j flag only available in version 2.8+):

    git clone --recursive -j8 git://github.com/foo/bar.git
    cd bar
    

    With version 1.6.5 of Git and later, you can use:

    git clone --recursive git://github.com/foo/bar.git
    cd bar
    

    For already cloned repos, or older Git versions, use:

    git clone git://github.com/foo/bar.git
    cd bar
    git submodule update --init --recursive
    
    0 讨论(0)
  • 2020-11-22 06:12

    You have to do two things before a submodule will be filled:

    git submodule init 
    git submodule update
    
    0 讨论(0)
  • 2020-11-22 06:21

    Try this.

    git clone -b <branch_name> --recursive <remote> <directory>
    

    If you have added the submodule in a branch make sure that you add it to the clone command.

    0 讨论(0)
提交回复
热议问题