列出git特定远程仓库的分支

4

我已经在一个项目中添加了多个远程仓库。

如何检查特定分支并将代码推送到该分支的远程仓库?

例如:

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)

这里新增了两个远程分支。 目前我只有原始分支,没有隐藏分支。

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

当我执行 git branch -a 命令时,我只能看到来自原始仓库的分支。

我需要一个命令来列出隐藏远程分支。


1
git pull stash <branch-name>git push stash <branch-name>。虽然stash不是远程的好名称... - Vishwanath
1
@Vishwanath,我怎样可以检查stash的分支? - KKB
1
git checkout -b <branch-name> stash/<branch-name> - Vishwanath
1
@Vishwanath,使用 git checkout -b <branch-name> stash/<branch-name> 命令创建了一个新分支,但问题并未解决。 - KKB
1
解决了您的问题吗?我应该将其添加为答案吗? - Vishwanath
显示剩余4条评论
2个回答

3
这是步骤如下:
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>

这并没有为分支列表选择特定的远程,但问题询问了一个“特定”的远程,所以我认为这并没有回答原始问题。当有7个远程时,其中两个来自上游维护者,branch -a列表变得非常长(在我的情况下有1624行)。所以,只是说一下,答案可能会更好;-) - Philip Oakley

1
根据Ævar在Git列表上对我提问的回复:https://public-inbox.org/git/87lfz3vcbt.fsf@evledraar.gmail.com/
有没有一个命令或者简单的分支调用,如branch、show-ref、for-each-ref等,可以给定一个分支模式和远程名称,快速筛选出潜在分支列表中仅为一到两个24行屏幕?

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

后者将与您可能已经以“.”为前缀的任何本地分支混合在一起。

之所以这不是某些命令中的简易模式,是因为没有一个硬性概念表明给定的远程“拥有”给定的一组 RTB。这只是惯例,但有时它们可以重叠。


记得在模式中使用适当的*元素。这不是子字符串搜索。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接