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

1vi .git/hooks/post-commit

Add

1
2
3
#!/bin/sh 

git push origin master

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

[[email protected] vshare]# cat .git/hooks/post-commit

!/bin/sh

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

Leave a Comment

Pin It on Pinterest

Share This
Open chat