Writing Better Commit Messages
Generate meaningful commit messages — Conventional Commits, scope, body, footer.
What You Will Learn
- Generate commit messages with Copilot.
- Follow Conventional Commits format.
- Write meaningful scope and body.
- Reference issues in footer.
- Avoid generic messages.
Why This Matters
A good commit message tells future you (and reviewers) why a change was made. Copilot can draft them in seconds — but only if you prompt well and verify the result actually describes what changed.
Concept Explained
Conventional Commits is a format: `type(scope): subject` followed by body and footer. Types: feat, fix, docs, refactor, test, chore, perf, style. Copilot can generate these from your staged diff.
How It Works
Stage your changes (git add). In VS Code's Source Control panel, click the ✨ icon to generate a commit message. Copilot reads the staged diff and proposes a Conventional Commits message. Edit before committing.
Step-by-Step Tutorial
1. Stage changes
git add the files you want to commit.2. Generate message
In Source Control, click ✨ or use command 'GitHub Copilot: Generate Commit Message'.3. Verify
Read the message. Does it accurately describe the change?4. Edit if needed
Adjust type, scope, or subject to match your project's conventions.5. Reference issue
Add footer: 'Refs #123' or 'Fixes #123'.Real-World Example
A team adopted Copilot-generated commit messages with Conventional Commits. PR descriptions became auto-generated from commits. Release notes auto-generated from feat/fix types. Time spent on release notes dropped from 2 hours to 15 minutes per release.
Example Prompts / Commands / Code
feat(auth): add JWT-based authentication
Adds login, logout, and token refresh endpoints. Tokens expire in 1 hour.
Uses HS256 algorithm. Adds dependency on jsonwebtoken.
Refs #142
fix(parser): handle empty input without throwing
docs(api): document the /users endpoint
refactor(auth): extract token validation to middleware
test(utils): add edge case tests for formatDate
chore(deps): bump express to 4.19.0
perf(db): add index on users.email
Common Mistakes
- Accepting generic messages like 'update code'.
- Missing the type prefix — breaks tooling that parses Conventional Commits.
- Subject too long — keep under 72 chars.
- Forgetting the issue reference in the footer.
Best Practices
- Always review generated messages; edit if generic.
- Use Conventional Commits types consistently.
- Keep subject under 72 chars; use imperative mood ('add', not 'added').
- Include body for non-trivial changes explaining the 'why'.
- Reference issues in the footer.
Troubleshooting
| Problem | How to Fix |
|---|---|
| Generated message is generic | Stage more granular changes — too much in one commit confuses Copilot. |
| Wrong type | Edit manually. Or train Copilot with .github/copilot-instructions.md specifying your conventions. |
Practical Exercise
Your Turn
Make a small change to a project. Stage it. Generate a commit message with Copilot. Edit it to follow Conventional Commits. Add an issue reference. Commit.
Key Takeaways
- Copilot generates Conventional Commits messages from staged diff.
- Always review and edit generic output.
- Use consistent types: feat, fix, docs, refactor, test, chore.
- Keep subject under 72 chars; explain 'why' in body.
- Reference issues in footer.
Frequently Asked Questions
Does Copilot generate PR descriptions too?
Can I customize the format?
Further Reading
Official References
SEO Metadata
SEO title: Writing Better Commit Messages
Meta description: Generate meaningful commit messages — Conventional Commits, scope, body, footer.
Primary keyword: writing better commit messages
Secondary keywords: writing better commit messages
Search intent: Informational
URL slug: /copilot-writing-better-commit-messages
Categories: AI Tools, GitHub Copilot
Tags: GitHub Copilot, Beginner, Git, Commit Messages, Conventional Commits, IMCSEIAN, Tutorial, IMCSEIAN
Featured image concept: IMCSEIAN lesson card for Writing Better Commit Messages
Comments
Comments
Post a Comment