列出 git 中特定远程的分支

List branches of particular remote in git

我在一个项目中添加了多个远程。 如何使用分支检查特定分支并在该远程上推送代码。

例如。

origin  https://example1@bitbucket.org/username/repo.git (fetch)
origin  https://example1@bitbucket.org/username/repo.git (push)
stash   http://example2@stash.xyz.com/scm/omed/repo.git (fetch)
stash   http://example2@stash.xyz.com/scm/omed/repo.git (push)

这里添加了两个远程。 目前我只有 origin 分支没有 stash 分支。

我想列出特定远程的所有分支。

当我执行 git branch -a 时,我只看到来自 origin

的分支

我需要列出隐藏远程分支的命令。

遵循以下步骤。

1) 获取远程信息。 stash 在这种情况下是远程名称。

git fetch stash

2) 显示远程分支

git branch -a

3) 现在您可以创建本地分支,由远程分支跟踪,如下所示。

git checkout -b <branche-name>  stash/<branch-name>

4) 使用远程名称拉取或推送

git pull stash <branch-name>
git push stash <branch-name>

根据 Ævar 对我在 Git 列表中询问的回复:https://public-inbox.org/git/87lfz3vcbt.fsf@evledraar.gmail.com/


Is there a command or simple simple invocation of branch, show-ref, for-each-ref, etc that can be give a branch pattern and remote name to quickly filter down the list of potential branches to just one or two 24-line screens?

那是:

git branch -a -l '<remote>/<pattern>'
git for-each-ref 'refs/remotes/<remote>/<pattern>'

后者会与您碰巧遇到的任何本地分支机构混为一谈 前缀为 .

在某些命令中这不是简单模式的原因是因为有 没有硬性概念,即给定的遥控器 "owns" 给定的 RTB 集。它是 只是约定俗成,但有时它们可​​以而且确实会重叠。


记得在模式中使用适当的 * 元素。这不是 sub-string 搜索。