Created
February 6, 2022 19:37
-
-
Save 9ete/9597998bf4b653eb3f3094a80816927f to your computer and use it in GitHub Desktop.
Gchk bash function to extend on git checkout
This file contains hidden or 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
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