How do I set git to automatically push to a remote repo (including automatically providing my passphrase) after each commit to the local repo?
First, make sure that you can push manually without providing your password. If you are pushing over HTTP or HTTPS, that will be a case of either creating a .netrc file with the login details or adding your username and password into the URL for the remote. If you're using SSH, you can either create a keypair where the private key doesn't have a password, or use ssh-agent to cache your private key.
.netrc
ssh-agent
Then you should create an executable (chmod +x) file in .git/hooks/post-commit that contains the following:
chmod +x
.git/hooks/post-commit
#!/bin/sh git push origin master
... customizing that line if you want to push to a remote other than origin, or push a branch other than master. Make sure that you make that file executable.
origin
master
2.1m questions
2.1m answers
60 comments
57.0k users