I'm having trouble getting git to ignore my wp-config.php
file on deployments. I set up automated deployments with git (it's a really great tool, if you don't know about it you can read about it here - you don't need to be using kinsta hosting like the article indicates, although your file structure may vary).
But every time I push changes, it overwrites my wp-config.php
file, causing a database error on the site. This happens because the git hook used for deployments introduces the changes, then checks out any local changes. Since this is a staging site, it uses the repo from production, but has different values in wp-config.php
, in order to connect to its own database.
What I've tried so far:
- committing the changes to wp-config on the staging server, so it won't get checked out by the git hook
- adding
wp-config.php
to.gitignore
(I should've done originally) on staging server - adding
wp-config.php
to.gitignore
(I should've done originally) on development and pushing to staging - adding a line to the
post-receive
hook to checkout the changes towp-config.php
after the deployment is performed
Here's my post-receive
hook file (client name replaced with XXXXX):
#!/bin/bash
TARGET="/www/XXXXX_975/public"
GIT_DIR="/www/XXXXX_975/private/XXXXX.git"
BRANCH="master"
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 staging..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
git checkout /www/XXXXX_975/public/wp-config.php
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
The site lives in the public
directory. The repo is in a different directory private
so as not to be overwritten by deployments.
This is a Wordpress website, hosted on Kinsta. Let me know if there's any information I forgot to include.
Thank you!