2

我正在编写 shell 脚本来git从远程仓库部署一个分支。

这是我正在使用的命令:

   git clone -q --depth=1 https://my.repourl.com/git-repo.git /my/destination/folder -b develop

问题是,如果分支(在这种情况下为开发)是错误的,它只是忽略并从主分支中提取(?)。我收到这条消息:

  warning: Remote branch devel not found in upstream origin, using HEAD instead

我只想让 git 死/退出,如果它没有找到指定的分支。有什么标志吗?或者有什么替代方案?git-archive由于某种原因没有工作。

4

2 回答 2

1

正如twalberg 评论git ls-remote --heads https://my.repourl.com/git-repo.git是用于检查远程端是否存在分支的命令。

问题“如何检查给定远程存储库上是否存在远程分支? ”列出了另一种可能性:

git clone -n
git fetch
# parse git branch -r

测试(bash)可能如下所示:

br=$(git ls-remote --heads https://my.repourl.com/git-repo.git|grep abranch)
if [[ "${br}" != "" ]]; then
  git clone -b aBranch ...
fi
于 2013-03-13T19:47:07.090 回答
0

我得到的行为与 Kevin 使用 git v1.7.1 发布的行为相同 - 但是在使用 git v2.12.0 进行测试时,当指定不存在的分支时 ,克隆命令实际上会失败:

$ git clone --depth 1 -b FakeBranch --bare gitserver:/repo.git
Cloning into bare repository 'repo.git'...
warning: Could not find remote branch FakeBranch to clone.
fatal: Remote branch FakeBranch not found in upstream origin
于 2018-11-23T11:09:38.377 回答