Writing Better Git Commit Messages in Laravel Projects
How following a simple convention can make your project easier to maintain and collaborate on
One of the small things that makes a big difference over time is how you write your commit messages.
If you’ve ever tried to track down the cause of a bug or understand why something changed months later, you know how frustrating a vague commit like update stuff
can be. And if you're working in a team or maintaining open source code, this only gets worse.
The solution? Use conventional commit prefixes, a simple system that helps make your history more useful, especially when working in Laravel or similar PHP projects.
The Core Idea: Prefix Your Commits with Purpose
Conventional commits use a consistent format like this:
type(scope): short description
Where:
type
is the nature of the change (feat
,fix
,chore
, etc.)scope
is optional, but helps clarify where the change applies (e.g.routes
,auth
,queue
)description
is what actually changed, in plain language
Example:
feat(auth): allow login via username or email
This one-line change tells you it’s a new feature, it touches the authentication system, and what it does.
Common Prefixes and When to Use Them
Prefix | Use when... | Example |
---|---|---|
feat | You’re adding a new feature | feat(cli): add --dry-run mode |
fix | You’re fixing a bug | fix(env): default fallback wasn't applying |
refactor | You’re changing code structure with no behavior change | refactor(queue): extract job handler logic |
chore | You’re doing maintenance tasks | chore(lockfile): update dependencies |
docs | You’re improving documentation | docs(readme): clarify deployment steps |
test | You’re adding or changing tests | test(api): add test coverage for error responses |
ci | You’re updating GitHub Actions or CI config | ci: add cache for Composer packages |
build | You’re making changes to the build process | build: add Dockerfile for local dev |
It’s straightforward, but it pays off immediately when scanning git log
or reviewing pull requests.
Why It’s Worth Using
Here’s why I’ve started using it in my Laravel projects:
- It makes my commit history searchable and readable.
- It improves the quality of pull requests.
- It helps versioning tools like semantic-release generate changelogs and bump versions automatically.
- It makes collaborating easier. People understand what changed before reading a single line of code.
It’s also something people like Nuno Maduro and other Laravel core contributors use routinely, even if informally. It’s a good standard to follow.
Add a Commit Linter (Optional but Recommended)
If you want to enforce this across your team, you can use Husky and commitlint to block non-conforming messages:
npm install --save-dev husky @commitlint/{cli,config-conventional}
npx husky install
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
Add this config file:
// commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional'],
};
Now your commits will get linted automatically. No more vague or unclear messages slipping into your history.
Final Thoughts
This isn't about being overly strict. It’s about being clear. Good commit messages are a low-cost way to make your project easier to understand and work on, especially as it grows.
Whether you're solo or working with a team, adopting a consistent format makes a difference. If you're using Laravel or any PHP framework, there's no downside to starting with conventional commits.
It takes a few seconds per commit. But over time, it saves hours of confusion and rework.