Skip to content

Instantly share code, notes, and snippets.

@christianb
Created November 1, 2017 10:21
Show Gist options
  • Save christianb/26da2ea1534dff9f2ca58bdf6777f9de to your computer and use it in GitHub Desktop.
Save christianb/26da2ea1534dff9f2ca58bdf6777f9de to your computer and use it in GitHub Desktop.
Easy checkout of branch using grep
# !/bin/sh
# Easy checkout of branch using grep.
#
# example: chkBranch 1789
# or: chkBranch ZAC-4
git pull
count=`git branch | grep -c $1`
if [ $count -eq 1 ]
then
echo "just one, check it out"
branch=`git branch | grep $1`
echo $branch
git checkout $branch
git pull
exit 0
fi
# check if there is a remote branch
if [ $count -eq 0 ]
then
echo "no branch with name $1 exists, trying to check out remote branch"
branch=`git branch -a| grep $1`
stripped=`echo ${branch:17}`
git checkout $stripped
git pull
exit 0
fi
echo "found more than one branch: "
git branch | grep $1 | while read -r line ; do
var=2
echo "$line"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment