2017-04-05 62 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上自己。