Skip to content

Instantly share code, notes, and snippets.

@prmichaelsen
Created April 16, 2024 17:48
Show Gist options
  • Save prmichaelsen/61f773aee304939af9d2c7960bf11b66 to your computer and use it in GitHub Desktop.
Save prmichaelsen/61f773aee304939af9d2c7960bf11b66 to your computer and use it in GitHub Desktop.
Git force push
gitf ()
{
prefix="dev/$USER/"
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$branch" = $prefix* ]]; then
echo "[INFO]: Force pushing to branch '$branch'..."
git push origin ":$branch" ; git push origin -u "$branch"
else
echo "[INFO]: Cannot push to branch '$branch' because it does not match prefix '$prefix'."
}
# My workplace disables forcing pushing on all branches
# in the repository which is stupid because some people
# use remote repos to back up their dev branches.
# They allow deleting branches, however, so essentially
# they allow force pushing, but with extra steps.
#
# This script removes the extra steps and guards
# against you accidentally trying to force push against
# a non-dev branch.
#
# Remember, guardrails that impede workflows, do not
# offer any real benefit, and can easily be circumvented
# are not guard rails at all--they are liabilities.
#
# This script is a guardrail against the liability
# created by the dogmatic universal "no force push"
# guardrail.
#
# I fly in the face of Providence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment