Skip to content

Instantly share code, notes, and snippets.

@9ete
Created February 6, 2022 19:37
Show Gist options
  • Save 9ete/9597998bf4b653eb3f3094a80816927f to your computer and use it in GitHub Desktop.
Save 9ete/9597998bf4b653eb3f3094a80816927f to your computer and use it in GitHub Desktop.
Gchk bash function to extend on git checkout
function gchk() {
if [[ $1 == "-h" ]]; then
echo "\nThis function will checkout the branch or prompt the user to create the branch of it does not exist"
return
fi
if [[ $1 == "-b" ]]; then
git checkout -b ${2}
return
fi
{ # try
git checkout ${1} &&
} || { # catch
echo "Would you like to create the branch? (Y/n)"
read yn
case $yn in
[Nn]* ) echo "branch not created";;
[Yy]* ) git checkout -b ${1};;
* ) git checkout -b ${1};;
esac
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment