2017-05-04 19 views

回答

2

如果这些子模块仓库有自己的我的分支,他们可以declared to follow that branch

cd /path/to/your/parent/repo/Foo 
git config -f .gitmodules submodule.bar1.branch my-branch 
git config -f .gitmodules submodule.bar2.branch my-branch 

git submodule update --remote 

但是,这涉及重复,每次你检出父回购的一个分支。

torek指出in the comments这些子模块可能有自己的子模块,因此需要--recursive选项。

你也可能要添加--recursive和/或--no-fetchgit submodule update --remote命令。
而不是单独的git config -f操作,您可能需要git submodule foreach,也可能需要--recursive

git submodule foreach -q --recursive 'git config -f $toplevel/.gitmodules submodule.$name.branch my_branch' 

在多行以便于阅读:

git submodule foreach -q --recursive \ 
    'git config -f $toplevel/.gitmodules submodule.$name.branch my_branch' 

然后你就可以检出每个子模块到分支:

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

在多行以便于阅读:

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

您可能还想在'git子模块更新--remote'命令中添加'--recursive'和/或'--no-fetch'。不是单独的'git config -f'操作,你可能需要'git submodule foreach',也许可以用'--recursive',尽管让右边看起来很棘手。 – torek

+0

我同意并将在稍后编辑(我正在上下班)我只是提出了一个解决方案的开始,提到了遵循子模块的分支的可能性。 – VonC

+0

感谢您的回复。我已经赞赏你的帮助,但是我已经创建了一个脚本,子模块将遵循主要的仓库分支。 –

相关问题