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
If your branch names are very specific, you might not need to use grep for simple branch name matching:
git ls-remote --heads $(git remote | head -1) "*${BRANCH_NAME}*" | \
cut -d$'\t' -f2 | \
sed 's,refs/heads/,,' | \
wc -l
which works for
BRANCH=master
BRANCH=mas
BRANCH=NonExistingBranch (returns 0)
BRANCH=ISSUE-123
We use unique issue id as branch names and it works fine.
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.