Skip to content

Instantly share code, notes, and snippets.

@willsantos
Last active March 5, 2022 15:52
Show Gist options
  • Save willsantos/3c7da8c383fb8b1a9fd6e5817924b334 to your computer and use it in GitHub Desktop.
Save willsantos/3c7da8c383fb8b1a9fd6e5817924b334 to your computer and use it in GitHub Desktop.
Hook to block Main branch
#!/bin/bash
red='\x1b[41m'
nocolor='\x1b[0m'
protected_branch='main'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
echo -e "${red}You are in the $current_branch,Blocked Branch${nocolor}"
read -p "Do you really want to do this? [y/n]" -n 1 -r < /dev/tty
echo
if echo $REPLY | grep -E '^[Yy]$' > /dev/null
then
exit 0 # Do run
fi
exit 1 # dont run
else
exit 0 # Do run
fi
@willsantos
Copy link
Author

Não esquecer de dar permissão de escrita

chmod +x .git/hooks/prepare-commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment