Git version control is a safe and fast way to deploy code changes—such as themes, custom plugins, and Composer dependencies—from your local development environment to Seravo's production or staging servers.
Prerequisites
Before deploying changes, ensure the following are in place:
Working SSH connection: Your public SSH key has been added to the server and you can connect to the site via SSH.
Local Git repository: Your site's codebase has been cloned to your local workstation (see Cloning a Site to Your Local Development Environment and Using Git if needed).
Step 1: Check or Add a Git Remote
Navigate to your project directory on your local machine and inspect your configured Git remotes:
git remote -v
If you cloned the project directly from Seravo's server, a remote named production is already configured:
production ssh://<ssh-user>@<site>.seravo.com:<ssh-port>/data/wordpress (fetch)
production ssh://<ssh-user>@<site>.seravo.com:<ssh-port>/data/wordpress (push)
If production is missing (for example, if you cloned the repository from GitHub or GitLab), add it with:
git remote add production ssh://<ssh-user>@<site>.seravo.com:<ssh-port>/data/wordpress
Similarly, you can add your staging environment using its dedicated SSH port: git remote add staging ssh://<ssh-user>@<site>.seravo.com:<staging-ssh-port>/data/wordpress.
Step 2: Deploy Changes (git push)
Commit your local changes to Git and push them to the production server:
git add .
git commit -m "Descriptive message explaining the changes"
git push production master
If your local repository uses main as its default branch and the server does not have a separate main branch, push your local main directly to the server's master like this:
git push production main:master
Automating Post-Deployment Tasks (post-receive Hook)
By default, git push only transfers modified files to the server. To ensure your site reflects all changes immediately after deployment, automate essential build and cache-purging tasks on the server side:
Composer dependencies: Install packages defined in
composer.json(composer install --no-dev).Asset compilation (Build): Compile theme CSS and JavaScript assets (such as
npm run buildorgulp build) if compiled files are not committed directly to Git.Cache purging: Flush the WordPress object cache and nginx page cache so updates become visible to visitors immediately.
Seravo's WordPress project template includes a sample script at /data/wordpress/scripts/git-hooks/post-receive. You can also create or edit /data/wordpress/.git/hooks/post-receive directly on the server:
#!/bin/bash
set -e
echo "Running post-receive deployment tasks..."
# Install Composer dependencies (if composer.json is present)
if [ -f "/data/wordpress/composer.json" ]; then
cd /data/wordpress && composer install --no-dev --optimize-autoloader
fi
# Build theme assets if applicable (update path to match your theme)
if [ -f "/data/wordpress/htdocs/wp-content/themes/your-theme/package.json" ]; then
cd /data/wordpress/htdocs/wp-content/themes/your-theme && npm run build
fi
# Flush WordPress object cache and nginx page cache
wp cache flush --path=/data/wordpress/htdocs
wp-purge-cache
Grant execution permissions to the script on the server via SSH so Git runs it automatically after every git push:
chmod +x /data/wordpress/.git/hooks/post-receive
Learn more about available automation options in Using Git Hooks.
Database and Media Files (uploads)
Git version control is intended strictly for your site's source code (themes, custom plugins, and configuration files). A Git deployment does not transfer the database or media files stored in wp-content/uploads.
Do not commit media files or database dumps to Git: Large binary files rapidly bloat the repository size and slow down cloning and deployments.
Transfer media using dedicated tools: To transfer media files between environments, use
rsyncorscpover SSH.Avoid overwriting the production database: Never import a local development database directly into production if the live site has received new orders, form submissions, or posts. Apply content or configuration updates in production safely through the WordPress dashboard or WP-CLI commands.
Common Issues and Troubleshooting
git pushfails withrefusing to update checked out branch: By default, Git prevents pushing to a branch that is currently checked out in a non-bare repository. Enable automatic working tree updates on the server via SSH:cd /data/wordpress && git config receive.denyCurrentBranch updateInstead
The
post-receivescript does not execute after pushing: Verify that the file has execution permissions (chmod +x /data/wordpress/.git/hooks/post-receive) and is saved with Unix line endings (LF).git pushreturnserror: src refspec master does not match any: Your local primary branch is likely namedmaininstead ofmaster. Deploy your changes usinggit push production main:master.SSH connection fails with
Permission denied (publickey): Ensure your public SSH key has been added to~/.ssh/authorized_keyson the server and that your SSH username and port match your site's credentials.
See Also
Git deployments combined with automated post-receive hooks make pushing updates to production fast, consistent, and reliable. If you need assistance configuring Git remotes, hook scripts, or SSH access, our support team is happy to help at [email protected].
