Set branch for all Git Submodules

后端 未结 2 1095
伪装坚强ぢ
伪装坚强ぢ 2021-01-14 06:47

Is there a command to set the same branch name for all existing Git Submodules

git submodule add -b develop *

Basically I need a w

相关标签:
2条回答
  • 2021-01-14 07:44

    See git submodule foreach.

    Evaluates an arbitrary shell command in each checked out submodule.

    git submodule foreach git checkout -b develop
    
    0 讨论(0)
  • 2021-01-14 07:53

    Looking for a way to recursive set the branch in the .gitmodules file

    With Git 2.22 (Q2 2019, four years later), you will be able to use git submodule set-branch -b <abranch>, because "git submodule" learns "set-branch" subcommand that allows the submodule.*.branch settings to be modified.

    See commit b57e811, commit c89c494 (08 Feb 2019), and commit 7a4bb55 (07 Feb 2019) by Denton Liu (Denton-L).
    (Merged by Junio C Hamano -- gitster -- in commit 01f8d78, 25 Apr 2019)

    submodule: teach set-branch subcommand

    This teaches git-submodule the set-branch subcommand which allows the branch of a submodule to be set through a porcelain command without having to manually manipulate the .gitmodules file.

    In your case, for all submodules, using git submodule foreach:

    git submodule foreach 'git submodule set-branch --branch aBranch -- ${sm_path}'
    git submodule foreach 'git submodule set-branch --default -- ${sm_path}'
    

    (the last line set the 'master' branch, which is the default)


    Before Git 2.22, you would use the command I mentioned in "How can I specify a branch/tag when adding a Git submodule?"

     git submodule foreach 'git config -f .gitmodules submodule.${sm_path}.branch <branch>'
    

    Note: Git 2.24 (Q4 2019) makes clear the --default and --branch options are mutually exclusive.

    See commit 40e747e (16 Sep 2019) by Denton Liu (Denton-L).
    (Merged by Junio C Hamano -- gitster -- in commit 7f17913, 07 Oct 2019)

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