Git workflow for PHP developers: how to stop fearing conflicts and love code review
\n\nHave you ever spent half a day merging branches only to end up with a "fatal error" in production? Or maybe your colleague accidentally pushed raw code straight to master, and you found out about it when the site went down? If so — welcome to the club. But the good news is that 90% of such problems are solved by a proper Git workflow for PHP developers.
\n\nIn this article, we won't just rehash the documentation. We'll break down real scenarios: how to organize branches, when to use rebase and when to use merge, and how to set up processes so the team doesn't get confused with commits. Let's go!
\n\nWhy "just git add . && git push" is evil
\n\nMany PHP developers, especially beginners, use Git like a "cloud flash drive." They commit everything indiscriminately, don't write meaningful messages, and push directly to master. This works exactly until the first conflict or until you need to roll back a change.
\n\nA proper git workflow php should solve three tasks:
\n- \n
- Isolation of changes — so a feature or bugfix doesn't break working code. \n
- Transparency — so any developer understands what's happening in the project. \n
- Automation — so tests and linters run before code reaches production. \n
Let's see how to implement this in practice.
\n\nChoosing a branching strategy: Git Flow, GitHub Flow, or something of your own?
\n\nFor PHP projects, there is no single correct answer. It all depends on the team size and release frequency. But there are two popular models.
\n\nGit Flow — the classic for large projects
\n\nIf you're working on a monolithic application with clear versions (e.g., a release once a month), Git Flow is your choice. Main branches:
\n- \n
master— only stable code matching production. \n develop— integration branch for all features. \n feature/*— each new feature. \n release/*— preparation for a release. \n hotfix/*— urgent fixes. \n
Example for a PHP developer: you're writing a payment module. You create a branch feature/payment-module from develop. After completion — a pull request into develop. When enough features have accumulated — you create release/2.3.0, where only bugfixes happen. Then you merge into master and develop.
GitHub Flow — for fast iterations
\n\nIf you have microservices or deploy several times a day, GitHub Flow is simpler:
\n- \n
main(ormaster) — always ready for deployment. \n - Any other branch — for a feature or bugfix. \n
- After a pull request and review — merge directly into
main. \n
For PHP, this is especially convenient when you have CI/CD set up: after merging into main, tests and deployment to staging or production run automatically.
\n\nWriting meaningful commits: examples in PHP
\n\nA commit is not just "save." It's a document by which you and your colleagues will reconstruct history. Use conventional commits:
\n\nfeat: add payment processing via Stripe\nfix: correct SQL query in user repository\nrefactor: extract validation logic to trait\n\n\nNow imagine you're working on a PHP project with Laravel. Let's say you added a new Artisan command. What commit would be useful?
\n\nfeat: add artisan command to sync expired subscriptions\n\n- Created SyncExpiredSubscriptions command\n- Added subscription:sync tag to schedule\n- Updated Subscription model with scopeExpired\n\n\nIn a month, you'll be able to quickly find when and why