Last active
June 1, 2020 19:18
-
-
Save davidimoore/0e31a959c8816fbb7b14f1d9c72eee6a to your computer and use it in GitHub Desktop.
"Safely" force push to remote origin branch.
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
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