Skip to content

Instantly share code, notes, and snippets.

@davidimoore
Last active June 1, 2020 19:18
Show Gist options
  • Save davidimoore/0e31a959c8816fbb7b14f1d9c72eee6a to your computer and use it in GitHub Desktop.
Save davidimoore/0e31a959c8816fbb7b14f1d9c72eee6a to your computer and use it in GitHub Desktop.
"Safely" force push to remote origin branch.
function git_force_push_w_lease() {
if [[ -z "$1" ]]; then
BRANCH=$(git symbolic-ref --short -q HEAD)
elif [[ "$1" == "master" ]] || [[ $BRANCH == "master" ]] || [[ $BRANCH == "production" ]]; then
echo "Attempted to force push to a restricted branch. Not allowed! Exiting"
return
else
BRANCH="$1"
fi
echo "Pushing to $BRANCH"
git push -u --force-with-lease origin $BRANCH
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment