Git branching strategies for WordPress teams with feature and hotfix flows

Git branching for WordPress teams: feature, release and hotfix branches

When several developers commit to main of the same theme or plugin, unfinished work reaches the server and nobody knows what is in production. A branching model answers three questions: where new work happens, what is released, and how an urgent fix goes live without the unfinished features.

Problem: A team of three works directly on main, deployments include half-done features, and an urgent fix has to wait until everything else is ready.

Solution: Keep main equal to production and protect it, do every change on a short-lived feature/ branch merged through a pull request, and fix production bugs on a hotfix/ branch from main. Add a develop branch and release/ branches only if you ship versions on a schedule (Git Flow).

The simple model: main plus feature branches

git switch main
git pull
git switch -c feature/shipping-calculator

git add -A
git commit -m "Add the shipping calculator to the cart"
git push -u origin feature/shipping-calculator
# open a pull request into main, review, merge

git switch main
git pull
git branch -d feature/shipping-calculator

Each merge into main is deployable, and deployment can run from main automatically (see Git hooks for deployments to a VPS). For most client sites and in-house plugins this is all you need.

Git Flow: develop and release branches

For a plugin with numbered releases, develop collects the finished features, and a release branch freezes a version for testing:

git switch -c develop main
git push -u origin develop

# features branch off develop and are merged into develop

git switch -c release/1.5.0 develop
# bump the version in the plugin header and readme.txt, update the changelog
git commit -am "Version 1.5.0"
git switch main
git merge --no-ff release/1.5.0
git tag -a v1.5.0 -m "Version 1.5.0"
git switch develop
git merge --no-ff release/1.5.0
git push origin main develop --tags
git branch -d release/1.5.0

--no-ff keeps a merge commit, so the history shows where each release came in.

Hotfix

git switch -c hotfix/payment-redirect main
git commit -am "Fix the redirect loop after payment"
git switch main
git merge --no-ff hotfix/payment-redirect
git tag -a v1.5.1 -m "Version 1.5.1"
git push origin main --tags
git switch develop
git merge --no-ff hotfix/payment-redirect    # skip this in the simple model
git push origin develop
git branch -d hotfix/payment-redirect

Protect main

In GitHub (Settings, Branches) or GitLab (Settings, Repository, Protected branches), require a pull request with one approval and passing checks before merging into main, and forbid force pushes. Then the model is enforced, not just agreed.

NOTE: Long-living feature branches are the real problem in any model: the longer a branch lives, the harder the merge. Merge small pieces often, and hide unfinished features behind a setting instead of keeping them on a branch for weeks. Basic commands: essential Git commands.