1. Home
  2. Blog
  3. WordPress
WordPress

Version Control for WordPress Themes: A Simple Git Workflow for Agencies

A simple Git workflow for WordPress theme agencies: what to commit, topic branches, style.css versions and tags, ACF Local JSON, deploys and rollbacks.

Short answer

Keep one repository per theme, use a stable main branch with short topic branches and pull requests, bump the Version in style.css and tag every release, commit ACF Local JSON with the code, deploy from the repository, and roll back by redeploying a tag or reverting a commit.

In this article
  1. What goes in the repository, and what stays out
  2. A branching model that fits a small team
  3. Number every release
  4. ACF field groups belong in the repository too
  5. Deploy from the repository, never from a server edit
  6. Rolling back
  7. A release checklist
  8. FAQ

Key points

  • Version is a required style.css header in X.X or X.X.X format, so bump it and tag every release.
  • Use a stable main branch and short-lived topic branches; a long-running development branch is optional for small teams.
  • ACF Local JSON saves field groups as files in the theme, so commit them with the template that uses them.
  • Edit field groups on staging, deploy, then sync on live, and never edit theme files on the live server.
  • Roll back by redeploying the previous tag or using git revert, which records a new commit instead of rewriting history.

Many WordPress sites are still changed in the same way they were ten years ago. Someone logs into the server over FTP, edits a file, and uploads it. Or someone opens the theme editor in wp-admin and saves. It works until two people touch the same file, or a change breaks the site, and nobody can say what the file looked like yesterday.

Version control fixes this, and it does not need to be complicated. This post is the small Git workflow I recommend for agencies that build custom WordPress themes: what goes in the repository, how to branch, how to number versions, how to handle ACF field groups, how to deploy and how to go back when a release goes wrong. It is written for teams of one to five people, so I keep every rule short.

What goes in the repository, and what stays out

I keep one repository per theme, and the theme folder is the root. Inside it go the templates, the stylesheets, the scripts, the functions, the language files and the ACF Local JSON folder. Everything that is code or configuration written by the team belongs here.

These stay out:

  • The uploads folder. It is content, not code, and it is large.
  • The wp-config.php file. It holds database details and secrets.
  • Third-party plugins, and the WordPress core files.
  • Build output that can be rebuilt from source, such as compiled files, when your process allows it.
  • Editor and system files such as local notes or temporary files.

A .gitignore file lists the patterns Git should leave alone. One detail from the gitignore documentation catches many people: files that are already tracked are not affected by it. If a secret or a large file was committed by mistake, adding it to .gitignore is not enough. You must stop tracking it with git rm --cached, and if it contained a real secret, you must also change the secret, because it is still in the history.

If a change is not in version control, it is a rumour, not a release.

Own-ur-Rehman Sheikh

A branching model that fits a small team

The Git book describes two ideas that work well together. The first is the long-running branch: a branch that holds only stable code, often code that has been or will be released. The second is the topic branch, which the book describes as short-lived and used for a single feature or related piece of work. It says topic branches are useful in projects of any size, and that creating, merging and deleting them is cheap.

Those ideas are explained in the book’s chapter on branching workflows. For agencies, my version is this:

  1. The main branch is what is live. Nobody commits to it directly.
  2. One topic branch per change. A new section, a bug fix or a plugin integration each get a branch with a clear name.
  3. A pull request for every merge. A second person reads the diff, or the author reads it again after a break.
  4. A staging copy sits between. The branch is deployed to staging first, then merged and released.

Some teams add a long-running development branch for integration testing. The book describes this too, and says multiple long-running branches are not required. For a small team, I skip it. One main branch plus short topic branches is simpler to explain to a new developer, and there is less to forget.

Commit messages and branch names

Small habits make a history readable a year later. I write commit messages in plain words that say what changed and why, for example a short line that names the template and the fix. I name branches after the change, not the person, so the list of open branches reads like a to-do list. I also keep commits small. A commit that changes one thing is easy to review and easy to revert, while a commit that changes twenty things is neither.

The same applies to pull requests. I write two or three lines that say what the change does, which pages it touches and how to test it. That text becomes the memory of the team. When a bug shows up months later, the pull request is usually the fastest way to learn what was intended.

Number every release

A WordPress theme already has a place for its version. The theme developer handbook lists Version as a required header in style.css, written in X.X or X.X.X format. WordPress reads the number to tell whether a newer version exists. So the version in style.css is not decoration. It is the theme’s official identity.

My rules for it:

  • Bump the version in every release, even a small one.
  • Add a line to a CHANGELOG.md file in the same commit. One sentence per change is enough.
  • Create a Git tag for the release with the same number.

The Git book explains the two kinds of tag. A lightweight tag is just a pointer to a commit. An annotated tag is stored as a full object with the tagger’s name, date and a message, and the book recommends annotated tags for releases. It also says that git push does not send tags to the server by default, so you have to push them on purpose. Its page on tagging shows the commands. A tag turns a vague question such as which version is on the live site into one you can answer in a second.

ACF field groups belong in the repository too

If your theme uses Advanced Custom Fields, the field definitions are part of the theme. Treat them like code. The ACF documentation on Local JSON explains how: you create an acf-json folder in the theme, and ACF saves a JSON file there whenever a field group, post type, taxonomy or options page is saved in the admin. No manual export is needed. ACF loads those files on startup, and the documentation notes that the files can be committed to Git so several developers keep their field settings in step.

The same page describes the sync step. An item is available to sync when it is missing from the database, or when its JSON modified date is newer than the database. A tab appears above the list table so you can import the changes. Two practical rules follow from this:

  1. Edit field groups on the development or staging copy, not on the live site. The JSON file changes there, goes into a commit and reaches live by deployment.
  2. After a deploy, run the sync on live. Check the sync tab and import, so the database matches the files.

If someone edits a field group directly on live, the JSON on the server changes and the repository does not know. The next deploy then overwrites the change or creates a conflict. I describe the thinking behind field groups in one template per page with ACF, and the reasons I avoid page builders in why I stopped using page builders.

Deploy from the repository, never from a server edit

The point of all this is that the repository is the single source of truth. A deploy then means one thing: put the tagged version on the server. How you do that matters less than that you do it the same way every time. I accept a deploy script, a CI job or a controlled pull on the server. I do not accept a file edited by hand.

WordPress can help enforce this. The documentation for wp-config.php describes a DISALLOW_FILE_EDIT setting that turns off the plugin and theme file editor in the admin. It says this helps stop users from crashing the site and adds protection if an attacker reaches a privileged account. A related setting, DISALLOW_FILE_MODS, also blocks plugin and theme installs and updates from the admin, so use it only if you have another way to update. For a managed client site, I switch the file editor off.

Rolling back

A release will go wrong sometimes. The best plan is a rollback that takes minutes and needs no thinking. I use two methods.

  • Redeploy the previous tag. This is the fastest. The old version was already tested, and you know exactly what it contains.
  • Revert the bad commit. The Git manual for git revert says it records new commits that undo the changes of earlier ones. It does not alter existing commits, so it is safe for a shared branch. I prefer it to resetting history on any branch other people use.

One caution applies to reverting a merge commit. The manual says you must choose the mainline parent, and that later merges will not bring those changes in again unless you handle it. I keep merges rare and small, so this seldom matters, but I read that section before I try it.

Rolling back code does not roll back data. If a release changed content, orders or settings in the database, the code rollback will not undo that. So I take a database backup before any release that touches data, and I keep schema or content changes separate from theme releases when I can.

A release checklist

Step What I do Why
Branch Create a topic branch from main with a clear name Keeps each change separate and easy to review
Commit Small commits with plain messages, ACF JSON in the same commit History explains itself
Review Open a pull request and read the diff Catches mistakes before they reach staging
Stage Deploy the branch to staging and test key pages Real checks on a copy of the site
Release Merge, bump style.css version, add changelog line, tag Every version has a name and a note
Deploy Deploy the tag to live, then sync ACF if needed The server matches the repository
Check Test key pages and watch for errors after release Find problems while they are small

If you are moving an existing site to a new theme, the checks around redirects and indexing matter as much as the code. Rank Ray’s website migration SEO checklist covers that side, and it fits well with a release process like this one.

None of this is advanced Git. It is a small set of habits: branch, review, number, tag, deploy from the repository, and keep a way back. An agency that follows them can hand a site to another developer, or take it back after a year, without fear of what changed in between.

FAQ

What should I put in a WordPress theme repository?

The theme's templates, styles, scripts, functions, language files and ACF Local JSON folder. Leave out uploads, wp-config.php, third-party plugins, WordPress core and rebuildable build output.

Does adding a file to .gitignore remove it from Git?

No. The gitignore documentation says files that are already tracked are not affected. Use git rm --cached to stop tracking it, and change any secret that was committed.

Where does WordPress read the theme version from?

From the required Version header in style.css, written in X.X or X.X.X format. WordPress uses the number to tell whether a newer version exists.

How do ACF field groups work with Git?

ACF Local JSON saves each field group as a file in the theme's acf-json folder when you save it in the admin. Commit those files, then use the sync tab to import changes on other sites.

What is the safest way to undo a bad release?

Redeploy the previous tagged version, or use git revert, which records new commits that undo earlier ones and does not alter existing commits. Back up the database first if the release touched data.

Sources

  1. Pro Git: Branching Workflows
  2. Pro Git: Tagging
  3. Git documentation: gitignore
  4. Git documentation: git-revert
  5. WordPress Theme Handbook: Main stylesheet (style.css)
  6. ACF: Local JSON

Your turn · Rank Ray

Want to be found on Google and in AI answers?