我有一个巨大的 git 仓库,里面有很多分支。如果存储库中有分支,我需要通过 Jenkins 内部的 shell 命令进行检查。
我像这样克隆了单个分支
if `sshpass -p password git clone -b "${BRANCH}" --single-branch ssh://user@server/GIT/${REPO}.git`; then
echo "success"
else
echo "ERROR: There is no branch "${BRANCH}" inside repo "${REPO}""
exit 42
fi
它工作正常,但克隆一个分支仍然需要很多时间。有没有办法让它工作得更快(也许不克隆 repo 或如果找到分支则中断克隆)?
提前致谢
最佳答案
你可以解析
的输出git ls-remote http://user@server/GIT/${REPO}.git
来自其documentation :
Displays references available in a remote repository along with the associated commit IDs.
关于git - 检查 git repo 中是否存在分支而不进行克隆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43225291/