Git push deployment
Before you get started using git push to deploy changes to your site, we assume the following:
- You already have a website set up on Templ that you want to push changes to.
- You have an existing git repo that you want to push changes from, e.g. on a local development environment.
Prepare your site on Templ
First you need to create a bare git repo on your Templ site.
Connect to your site using SSH and create a bare git repo:
git init --bare wordpress.git
Then we need to add a script for the files to actually be updated when changes are pushed to the repo:
nano wordpress.git/hooks/post-receive
Insert following content:
#!/bin/bash
git --work-tree=/home/user_xxxx/app_xxxx --git-dir=/home/user_xxxx/wordpress.git checkout -f
The path to your work-tree and git-dir must be valid!
You can find the user and webroot of your site in the Templ Panel.
The
checkout -f in the hook force-checks-out your repo's files into the webroot (app_xxxx) on every push.
Files tracked in your repo overwrite the server's copies, while files not tracked in the repo (such as wp-config.php, uploads, or plugins installed on the server) are left in place.
Make sure everything you want to control from git is committed to the repo.Make the script executable:
chmod +x wordpress.git/hooks/post-receive
Add your remote repo to your local environment and push
Now we can go to our local git repo that we want to push changes from, and add our remote repo that's on Templ:
git remote add templ ssh://[email protected]:xxxxx/home/user_xxxx/wordpress.git
The remote must be entered like
ssh://<user>@<hostname>:<port>/<path>.
You can find the SSH credentials for your site in the Templ Panel.And now we can push changes to Templ like so:
git push templ main
If your repo uses the older master branch name instead of main, push that branch instead:
git push templ master
You can check your current branch name with git branch --show-current.