Auto push after git commit

Git hook allow you to perform tasks when some changes happen on a git repository. To automatically push code when you make a commit, create hook file .git/hooks/post-commit

vi .git/hooks/post-commit

Add

#!/bin/sh

git push origin master

Thats all. Unlike normal bash scripts, git hooks don’t need 755 permission to run.

Example

[root@lin vshare]# cat .git/hooks/post-commit
#!/bin/sh

git push origin master
[root@lin vshare]# ls -l .git/hooks/post-commit
-rwxrwxrwx 1 root root 37 Apr 27 15:31 .git/hooks/post-commit
[root@lin vshare]#

See git

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *