How to check if remote branch exists on a given remote repository?

后端 未结 14 1021
独厮守ぢ
独厮守ぢ 2020-12-02 11:04

I need to do a subtree merge for a specific branch, if it exists on a given remote repository. The problem is that the remote repository is not checked out locally, so I can

14条回答
  •  心在旅途
    2020-12-02 11:41

    I just tried this:

    git ls-remote --heads 2>/dev/null|awk -F 'refs/heads/' '{print $2}'|grep -x "your-branch"|wc -l
    

    This will return 1 if branch "your-branch" is found and 0 otherwise.

提交回复
热议问题