A WordPress agency starts using Git “properly” by running git init in /var/www/html/ and committing everything. Two weeks later the repo is 4GB because someone uploaded a 200MB PDF and wp-content/uploads/ is tracked. The merges conflict on wp-config.php between staging and production. Three plugin updates landed without going through a branch. The Git shape WordPress sites need is specific — what to track, what to ignore, and how branches map to environments.
What’s happening
WordPress doesn’t ship a .gitignore. Plugins write to disk at runtime (cache, uploads, updated plugin code). wp-config.php differs per environment. The default reflex of committing everything produces a repo that fights you on every push.
The correct Git boundary is:
- In the repo: theme code, agency-owned plugins or mu-plugins,
composer.jsonandcomposer.lock, deployment configs, an.env.exampletemplate. - Not in the repo: third-party plugins (Composer manages them),
wp-content/uploads/,wp-content/cache/, the WordPress core directory,.envfiles,wp-config.phpif it contains secrets.
The branch model that holds up: main is what’s live in production. Feature work happens on short-lived branches (feature/event-cpt, bugfix/header-spacing) merged via PR. Staging deploys from a staging branch (or develop — pick a convention) that’s promoted to main on release. Hotfixes branch from main, merge to both main and staging.
How to verify
Audit an existing WordPress repo:
cd /path/to/wp-site
# Check what's tracked
git ls-files | head -30
# Look for things that shouldn't be
git ls-files | grep -E '(wp-content/uploads|wp-content/cache|node_modules|\.env$|wp-config\.php)$'
# Repo size
git count-objects -vH
If wp-content/uploads/ shows up, that’s a multi-GB problem to clean up. If wp-config.php is tracked and contains real secrets, those need to rotate immediately.
Check the branch model:
git branch -r | head
git log --oneline main..staging 2>/dev/null | wc -l # how far behind main is staging?
If staging is ahead of main by 80 commits and main was last touched 6 months ago, the team has stopped promoting — that’s a process problem, not a tooling one.
What to do
The Git setup that holds up for a WordPress team.
- The minimum
.gitignore:
# WordPress runtime + content
/wp-content/uploads/
/wp-content/cache/
/wp-content/upgrade/
/wp-content/backup-db/
/wp-content/blogs.dir/
# Third-party plugins managed by Composer
/wp-content/plugins/*/
!/wp-content/plugins/agency-custom/
!/wp-content/mu-plugins/
# Environment + secrets
.env
.env.*
!.env.example
wp-config.php
# Build artefacts
/node_modules/
/vendor/
*.log
.DS_Store
-
For
wp-config.php, the right pattern is a trackedwp-config-sample.php(or use Bedrock’sconfig/directory) and a generated, untrackedwp-config.phpper environment. Secrets come from environment variables — see wp-config.php hardening. -
The branch model:
main ← production, only PR merges from staging
staging ← deployed to staging environment, target of feature PRs
feature/* ← short-lived, one-developer
hotfix/* ← branches from main for emergencies
- Feature workflow:
git checkout staging && git pull
git checkout -b feature/event-cpt
# ... work ...
git push -u origin feature/event-cpt
# Open PR targeting staging
# CI runs, reviewer approves, merges
# staging deploys automatically (see deployment automation)
- Release workflow:
# Staging is good, promote to production
git checkout main && git pull
git merge --no-ff staging
git tag v2.5.0
git push origin main --tags
# main deploys automatically to production
- Hotfix workflow:
git checkout main && git pull
git checkout -b hotfix/critical-cve
# ... fix ...
# PR targeting main, merge after review
# Then merge main back into staging to keep them in sync
git checkout staging && git pull
git merge main
git push origin staging
-
Pre-commit hooks via
pre-commitor Husky run PHPCS (WordPress coding standards) andcomposer normalize. Catch the obvious problems before they hit CI. -
For multi-site repos (agency portfolios), each site is its own repo — not branches of a monorepo. Branches map to environments, not sites. The shared template lives in a separate template repo that sites pull updates from periodically.
For the deployment pipeline that promotes branches to environments, see WordPress deployment automation and staging-to-production promotion.
Stack Harbor’s managed enterprise WordPress hosting practice sets up Git workflows for agency portfolios. If a team is stuck merging on wp-config.php weekly, we can replatform the workflow.