Created
January 7, 2021 02:10
-
-
Save khoipro/9fcef0d5a59c2a8c99ab81db63231a8a to your computer and use it in GitHub Desktop.
.git/hooks/post-receive to auto update when Git has changed to specific branch. Example folder with cPanel user.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -eu | |
| TARGET="/home/<username>/public_html/" | |
| GIT_DIR="/home/<username>/public_html/.git" | |
| BRANCH="production" | |
| while read oldrev newrev ref | |
| do | |
| # only checking out the master (or whatever branch you would like to deploy) | |
| if [[ $ref = refs/heads/"$BRANCH" ]]; | |
| then | |
| echo "Ref $ref received. Deploying ${BRANCH} branch to production..." | |
| git --work-tree="$TARGET" --git-dir="$GIT_DIR" checkout -f | |
| else | |
| echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server." | |
| fi | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To make it work, you must copy this file to folder .git/hooks and rename to post-receive. Remember to chmod 777 if needed.