Last active
December 8, 2020 14:34
-
-
Save emeric-martineau/0cdbeee6d2423eb9143a12f08b880478 to your computer and use it in GitHub Desktop.
Prompt if you don't have push set upstream
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
#!/bin/bash | |
# Check only if git commit | |
if [ "$1" = "push" ]; then | |
__OK_COLOR="\e[42m" | |
__CANCEL_COLOR="\e[41m" | |
__NORMAL_COLOR="\e[m" | |
__BRANCH_COLOR="\e[33m" | |
__BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
git ls-remote --exit-code . origin/${__BRANCH} 2> /dev/null 1>&2 | |
if [ $? -ne 0 ]; then | |
echo -en "Branch ${__BRANCH_COLOR}${__BRANCH}${__NORMAL_COLOR} doesn't yet pushed, would you like push it? [${__OK_COLOR}enter${__NORMAL_COLOR}/${__CANCEL_COLOR}ctrl+c${__NORMAL_COLOR}]" | |
read PUSH_OR_NOT | |
if [ $? -eq 0 ]; then | |
git push --set-upstream origin ${__BRANCH} | |
else | |
exit 1 | |
fi | |
fi | |
git "$@" | |
unset __BRANCH | |
unset __CANCEL_COLOR | |
unset __NORMAL_COLOR | |
unset __OK_COLOR | |
unset __BRANCH_COLOR | |
else | |
git "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment