forked from plume-lib/plume-scripts
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgit-find-branch
More file actions
executable file
·27 lines (21 loc) · 856 Bytes
/
git-find-branch
File metadata and controls
executable file
·27 lines (21 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
###
### This script has been moved to the git-scripts repository:
### https://github.com/plume-lib/git-scripts
###
echo "Please use $(basename "$0") from https://github.com/plume-lib/git-scripts ."
echo "You are using $0,"
echo "which is an obsolete version from https://github.com/plume-lib/plume-scripts ."
# Usage: git-find-branch REPO_URL BRANCH ...
# Prints either the first BRANCH that exists in REPO_URL,
# or else prints the default branch name if none of the given branches exists.
# Often, you can use the `git-clone-related` script instead of this one.
REPO_URL=$1
shift
for BRANCH in "$@"; do
if (git ls-remote --quiet --exit-code --heads "${REPO_URL}" "${BRANCH}" > /dev/null); then
echo "${BRANCH}"
exit 0
fi
done
git ls-remote --symref "${REPO_URL}" HEAD | awk '/^ref:/ {sub(/refs\/heads\//, "", $2); print $2}'