ulu ulu -4 years ago 150
Git Question

How to automatically push after committing in git?

How do I set git to automatically push to a remote repo (including automatically providing my passphrase) after each commit to the local repo?

Answer Source

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.

Then you should create a file in .git/hooks/post-commit that contains the following:

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download