Skip to content

Instantly share code, notes, and snippets.

@mlsteele
Created April 27, 2018 15:07
Show Gist options
  • Save mlsteele/128ec75fdce0ff1c181bf8b20768e66d to your computer and use it in GitHub Desktop.
Save mlsteele/128ec75fdce0ff1c181bf8b20768e66d to your computer and use it in GitHub Desktop.
Script to run 'git push origin currentbranch' but ask for confirmation first
# Add this to ~/.gitconfig
[alias]
# Force push this branch, but with a confirmation.
force = !~/bin/git-force-push-ask
#!/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