Last active
June 7, 2017 09:35
-
-
Save nolandc/512754745e6b8b88c657 to your computer and use it in GitHub Desktop.
Git select-branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list=$(git branch --list | grep -v \*) | |
declare -a branches=($list) | |
echo "Branches: " | |
for i in "${!branches[@]}"; do | |
printf "%s\t%s\n" "[$i]" "${branches[$i]}"; | |
done | |
printf "Enter the number of the branch you'd like to switch to: " | |
read branchIndex | |
branch=${branches[branchIndex]} | |
if [[ -z "$branch" ]]; then | |
echo "The value you entered does not correspond to a listed branch." | |
else | |
git checkout ${branches[branchIndex]} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment