Skip to content

Instantly share code, notes, and snippets.

@nolandc
Last active June 7, 2017 09:35
Show Gist options
  • Save nolandc/512754745e6b8b88c657 to your computer and use it in GitHub Desktop.
Save nolandc/512754745e6b8b88c657 to your computer and use it in GitHub Desktop.
Git select-branch
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