Last active
January 29, 2022 01:49
-
-
Save otakupahp/2a48a3ce3b475921207b740c804d1313 to your computer and use it in GitHub Desktop.
Automatic deploy using GIT
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 | |
| TARGET="/www/{site-folder}/public/wp-content/themes" | |
| GIT_DIR="/www/{site-folder}/private/warp.git" | |
| BRANCH="main" | |
| while read oldrev newrev ref | |
| do | |
| # only checking out the master | |
| 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 $BRANCH | |
| 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
NOTE: The article used offers configurations for Kinsta, but could be used anywhere
This is an updated file from https://anchor.host/automatic-git-deploy-with-kinsta-via-ssh/
The steps are:
git init..gitignorefile with common WordPress exclusions (plugins/themes/core files).git init --bare ~/private/{site-name}.gitcd ~/public; git init~/private/{site-name}.git/hooks/and named post-receive (see below example). This will deploy from the bare git to the ~/public/ directory whenever a git push is received.chmod +x ~/private/{site-name}.git/hooks/post-receivegit remote add production ssh://{site-name}@{site-ip}:{site-port}/www/{site-folder}/private/{site-name}.gitgit push -u production master.The code and paths must be updates as needed.
The original article had issues if you use a branch different of master, so I used this https://stackoverflow.com/questions/31147389/git-remote-fatal-you-are-on-a-branch-yet-to-be-born to fix it