如何检查给定远程存储库上是否存在远程分支?
  如果它存在于给定的远程存储库上,我需要为特定的分支进行子树合并。  问题是远程仓库没有在本地签出,所以我不能使用git branch -r 。  我所有的是一个远程地址,就像这个https://github.com/project-name/project-name.git 。  有没有办法只通过远程地址列出远程分支?  我找不到任何有用的:( 
实际上,您也可以指定要搜索的分支的名称:
$ git ls-remote --heads git@github.com:user/repo.git branch
  如果找到具有名称branch ,您将得到以下输出: 
b523c9000c4df1afbd8371324083fef218669108        refs/heads/branch
否则将不会发送任何输出。
  所以管道到wc会给你1或0 : 
$ git ls-remote --heads git@github.com:user/repo.git branch | wc -l
  或者你可以在git ls-remote上设置--exit-code标志,如果找不到匹配的refs,它将返回退出代码2 。 
git ls-remote --heads https://github.com/rails/rails.git
5b3f7563ae1b4a7160fda7fe34240d40c5777dcd    refs/heads/1-2-stable
81d828a14c82b882e31612431a56f830bdc1076f    refs/heads/2-0-stable
b5d759fd2848146f7ee7a4c1b1a4be39e2f1a2bc    refs/heads/2-1-stable
c6cb5a5ab00ac9e857e5b2757d2bce6a5ad14b32    refs/heads/2-2-stable
e0774e47302a907319ed974ccf59b8b54d32bbde    refs/heads/2-3-stable
13ad87971cc16ebc5c286b484821e2cb0fc3e3b1    refs/heads/3-0-stable
3df6c73f9edb3a99f0d51d827ef13a439f31743a    refs/heads/3-1-stable
f4db3d72ea564c77d5a689b850751ce510500585    refs/heads/compressor
c5a809e29e9213102351def7e791c3a8a67d7371    refs/heads/deps_refactor
821e15e5f2d9ef2aa43918a16cbd00f40c221e95    refs/heads/encoding
8f57bf207ff4f28fa8da4544ebc573007b65439d    refs/heads/master
c796d695909c8632b4074b7af69a1ef46c68289a    refs/heads/sass-cleanup
afd7140b66e7cb32e1be58d9e44489e6bcbde0dc    refs/heads/serializers
您可以在当前文件夹中使用的另一种方式,如果它是运行git repo
git branch -a | egrep 'remotes/origin/${YOUR_BRANCH_NAME}$'
上一篇: How to check if remote branch exists on a given remote repository?
下一篇: How to squash specific commits that have been pushed to remote?
