2017-04-05 107 views
3

我有一个巨大的git仓库,有很多分支。如果存储库中有分支,我需要通过Jenkins中的shell命令进行检查。检查分支是否存在于git仓库中,而不会生成克隆

我做单枝的克隆这样

if `sshpass -p password git clone -b "${BRANCH}" --single-branch ssh://[email protected]/GIT/${REPO}.git`; then 
    echo "success"  
else 
    echo "ERROR: There is no branch "${BRANCH}" inside repo "${REPO}"" 
    exit 42 
fi 

它workes正确的,但它仍然需要花费大量的时间去克隆一个分支。有没有办法让它工作得更快(也许没有制作回购克隆或者在发现分支的情况下中断克隆)?

在此先感谢

回答

2

您可以解析的

git ls-remote http://[email protected]/GIT/${REPO}.git 

输出从它documentation:关联提交ID的 沿

显示引用可远程仓库中。

+0

这太棒了!谢谢! –

0

要获得唯一的分支和没有标签或其他任何你需要做到这一点,

git ls-remote -h https://github.com/danielgindi/Charts.git 

P.S:与你的远程URL进行更换。

它的工作对我来说,

git ls-remote -h https://github.com/danielgindi/Charts.git 

a7c7bb4caf7e68e1713468c3a021d0860a587ac8 refs/heads/independent-scatter 
5b22fa99ef80f2004a7439ee6d3c1cfc9c4be010 refs/heads/legacy/v2 
f23e872e7573f8c79862ff4822cfc5683703d424 refs/heads/master 
03939328cd995043877f97daa1c75c0d5a3ab60c refs/heads/xcode-8.3 

检查出来Github上自己。