I just learned about git push --force-with-lease
. It\'s pretty awesome. But, of course, I don\'t use force that often, and so I\'m worried that I might forget a
My solution was to create a wrapper script, and use an alias so that I always use it in place of the real git
.
Whenever I try to git push -f
, I see the following:
⚡ git push -f
use this instead so you don't cause race conditions in the
repo: git push --force-with-lease
Some advantages of this script are:
--force-with-lease
, so i don't get nagged when i get it wronggit push --force
will work.How to implement it:
-f
git
These instructions assume Linux or Mac, running bash. I haven't tried this with zsh or Windows, but I assume it'll work there too.
~/.bash_profile
:
alias git=~/.git_wrapper.sh
~./git_wrapper.sh
:
#!/bin/bash
for arg in "$@"; do
if [ "$arg" = "push" ]; then
ispush=1
elif [ "$ispush" = 1 -a "$arg" = '-f' ]; then
echo "use this instead so you don't cause race conflicts in the repo: git push --force-with-lease"
exit 1
fi
done
git "$@"
With those changes, restart your terminal and git
should now get uppity when you try to force push.