How can I specify a branch/tag when adding a Git submodule?

前端 未结 12 1253
旧巷少年郎
旧巷少年郎 2020-11-21 06:39

How does git submodule add -b work?

After adding a submodule with a specific branch, a new cloned repository (after git submodule update --init

12条回答
  •  野性不改
    2020-11-21 06:40

    In my experience switching branches in the superproject or future checkouts will still cause detached HEADs of submodules regardless if the submodule is properly added and tracked (i.e. @djacobs7 and @Johnny Z answers).

    And instead of manually checking out the correct branch manually or through a script git submodule foreach can be used.

    This will check the submodule config file for the branch property and checkout the set branch.

    git submodule foreach -q --recursive 'branch="$(git config -f .gitmodules submodule.$name.branch)"; git checkout $branch'

提交回复
热议问题