git - 检查 git repo 中是否存在分支而不进行克隆

标签 git bash jenkins

我有一个巨大的 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/

相关文章:

git - 如何反转未提交更改的 git diff 输出?

git - git pull --rebase 和 git pull --ff-only 的区别

git - 在 Jenkins 中发布到 Artifactory 时使用 Git SHA 提交 ID 作为 Artifactory 版本号

bash - 检查 pwd 是否在 bash 中

java - AWS 中的生产级微服务架构

Jenkins 管道条件环境变量

git - Jenkins 无法访问本地 github 存储库

bash - 在 mongodb 查询中嵌入 bash 变量

macos - 如何通过运行脚本让我的所有终端/shell 重新加载它们的环境?

jenkins - 使用 Jenkins API 促进构建