2017-05-04 42 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

感謝您的回覆。我已經讚賞你的幫助,但是我已經創建了一個腳本,子模塊將遵循主要的倉庫分支。 –

相關問題