我正在编写shell脚本,以便从远程存储库部署git分支。
这是我使用的命令:
git clone -q --depth=1 https://my.repourl.com/git-repo.git /my/destination/folder -b develop问题是,如果分支(在本例中是develop)是错误的,它就会忽略并从主分支(?)中提取。我得到了这样的信息:
warning: Remote branch devel not found in upstream origin, using HEAD instead如果git找不到指定的分支,我只想让它死掉/退出。有什么标志吗?或者其他选择?由于某些原因,git-archive不能工作。
发布于 2013-03-14 03:47:07
作为twalberg comments,是用于检查远程端上是否存在分支的命令。
问题"How to check if remote branch exists on a given remote repository?“列出了另一种可能性:
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发布于 2018-11-23 19:09:38
我得到了与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 originhttps://stackoverflow.com/questions/15393004
复制相似问题