如何删除子模块的远程分支 (Git)

How to delete a remote branch of a submodule (Git)

在名为 Repo 的 Git 存储库中,有 4 个子模块:

git config --file .gitmodules --name-only --get-regexp path

submodule.A/lib1
submodule.A/lib2 
submodule.lib3 
submodule.lib4

假设在不再需要的 lib1 子模块上有一个名为 Prototype 远程分支

git submodule foreach 'git branch -a | grep -i prototype || true'

Entering 'path-to-lib1/lib1'
  remotes/origin/FeatureA
  remotes/origin/Prototype
Entering 'path-to-lib2/lib2'
  remotes/origin/FeatureB
Entering 'path-to-lib3/lib3'
Entering 'path-to-lib4/lib4'
  remotes/origin/FeatureC

如何从 lib1 子模块中 删除 这个 Prototype 远程分支?

我尝试了以下方法:

git push origin --delete Prototype

git push origin --delete origin/Prototype

git push origin --delete remotes/origin/Prototype

以上 3 个命令都给出了错误:

error: unable to delete 'Prototype': remote ref does not exist 
error: failed to push some refs to 'repo-path'

(我正在尝试了解子模块的主题,但我偶然发现了这个问题,我在网上搜索后找不到答案。)

如有任何command/suggestion的解释,我们将不胜感激。

将目录更改为子模块,然后 git push --delete origin Prototype

您将子模块中的分支作为独立存储库删除,而不是在超级项目中:

cd path-to-lib1/lib1
git branch -d Prototype
git push origin --delete Prototype
cd ../..  # back to superproject