Every time that Git carries out an action, it looks in the .git/hooks/ directory for a file with a particular name, and runs it. The file could actually be a symlink that points to a file somewhere else on the system.
The man page for githooks explains:
You can use any scripting language, such as Perl or Ruby, not just shell, and I don't think that the script has to follow any special format, so you can write whatever code is best or easiest to get the list of addresses and send emails. Some examples are quite long, but there's nothing wrong with writing something very simple.
There is a large example post-commit hook script to send emails (written in shell) provided with the Git documentation, in the file /usr/share/doc/git-core/contrib/hooks/post-receive-email - it gets a list of addresses stored in the repository settings file, using the git config utility.