Skip to content

Instantly share code, notes, and snippets.

@SrChach
Created June 17, 2019 16:46
Show Gist options
  • Save SrChach/580177853ef25a815b53cd36b93e1ad2 to your computer and use it in GitHub Desktop.
Save SrChach/580177853ef25a815b53cd36b93e1ad2 to your computer and use it in GitHub Desktop.
git_pre_push_hook

Git hooks

Git hooks live into .git/hooks folder in every git repo.

The name of each one tells us when the git hook it's gonna be executed, and the .sample extension in each one prevent its execution.

When we are going to execute a script in some part of git's lifecycle, we need to

  1. Find the file of the part of lifecycle that we need to override
  2. Remove the .sample extension for this file
  3. Write our own code to this file

In the pre-push example we've override the .git/hooks/pre-push file, and write an example to intercept the push with a confirmation message

read -p "Estás a punto de hacer push a un sub-proyecto. Estás seguro? [si|no] " -r < /dev/tty
echo
if [[ $REPLY = 'si' ]];
then
exit 0
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment