2026-02-25
To activate pre-push, rename .git/hooks/pre-push.sample to .git/hooks/pre-push
Example script:
branch_name=$(git symbolic-ref HEAD 2>/dev/null)
echo "$branch_name"
if [ "$branch_name" != "refs/heads/min-branch" ]; then
echo "You can't push this branch."
exit 1
fi
exit 0
should work given that this command:
git symbolic-ref HEAD 2>/dev/null
gives: refs/heads/min-branch
and:
git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
gives min-branch
2026-03-03
Check if prepush is activated or not
lsprep() {
if [[ -f ".git/hooks/pre-push" ]]; then
echo ".git/hooks/pre-push was found:"
echo "pre-push is activated"
else
if [[ -f ".git/hooks/pre-push.sample" ]]; then
echo ".git/hooks/pre-push was not found:"
echo "but .git/hooks/pre-push.sample was found:"
echo "pre-push is deactivated"
else
echo "Hmmmmm"
fi
fi
}
nprep() {
if [[ -f ".git/hooks/pre-push" ]]; then
echo ".git/hooks/pre-push was found:"
nvim .git/hooks/pre-push
else
if [[ -f ".git/hooks/pre-push.sample" ]]; then
echo ".git/hooks/pre-push was not found:"
echo "but .git/hooks/pre-push.sample was found:"
nvim .git/hooks/pre-push.sample
else
echo "Hmmmmm"
fi
fi
}