A Git auto push for Windows or Linux

Paul Sweeney · 12th January 2021

To add a post commit git webhook that can work on windows or *nix, create a file in the local repo clone directory ./.git/hooks/post-commit with the content…

  • On windows (search for the correct #! path on the local system if this doesnt work):
#!C:/Program\ Files/Git/bin/sh.exe
git push origin main
  • On *nix:
#!/bin/sh
git push origin main

:information_source: The ./.git/hooks/post-commit file is just on the local environment, so:

  • it won’t get pushed to upstream repo
  • this will need to be redone for each environment/repo clone

Automate commit message

To ease things further, pre-fill the commit message