Created
April 27, 2018 15:07
-
-
Save mlsteele/128ec75fdce0ff1c181bf8b20768e66d to your computer and use it in GitHub Desktop.
Script to run 'git push origin currentbranch' but ask for confirmation first
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
# Add this to ~/.gitconfig | |
[alias] | |
# Force push this branch, but with a confirmation. | |
force = !~/bin/git-force-push-ask |
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
#!/usr/bin/env bash | |
# Run 'git push origin currentbranch' but ask for confirmation first. | |
set -e # errexit | |
set -u # nounset | |
BRANCH="$(git rev-parse --abbrev-ref HEAD | xargs)" | |
echo "Force push '$BRANCH'?" | |
read -p "[y/N]: " CHOICE | |
case "$CHOICE" in | |
y|Y ) git push origin +$BRANCH ;; | |
n|N ) echo "canceled" ;; | |
* ) echo "canceled" ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment