I'm late to the party but wanted to add some information in case someone else wants to do this.
If you're running your own server as a git remote, you probably want to look into the post-receive
githook.
If you're using GitHub, you'll need to use GitHub Actions. The actions/starter-workflows repository has a lot of good examples of the YAML files you'll need for that.