Customizing GitHub Copilot in VS Code for Better Commit Messages
Writing structured commit messages improves code history readability, but manually crafting them can be time-consuming. With GitHub Copilot in VS Code, you can now automate commit message generation—and even customize Copilot’s suggestions.
In this post, I’ll show you how to configure GitHub Copilot to follow your preferred commit style using a configuration file or direct settings instructions.
🚀 Using GitHub Copilot for Commit Messages in VS Code
GitHub Copilot can generate commit messages even if you haven’t staged your changes.
Here’s how to use it:
- Ensure GitHub Copilot is installed in VS Code.
- Open the Source Control panel (
Cmd + Shift + G). - Click in the commit message input box—Copilot will suggest a commit message.
- Press
Cmd + Enterto accept and commit the suggestion.
Tip: If the suggestion isn't ideal, press
Cmd + Ito cycle through alternatives.
📝 Customizing GitHub Copilot’s Commit Message Generation
By default, GitHub Copilot generates Conventional Commits (e.g., feat:, fix:, docs:). However, you can customize its behavior in two ways:
- Using a configuration file (
.copilot-commit-message-instructions.md). - Directly entering instructions in VS Code settings.
🔧 Method 1: Using a Configuration File
Create a file named .copilot-commit-message-instructions.md in your project’s root directory and define the commit message format inside:
The first line should be a single line summary with no more than 50 characters.
The second line should be blank.
Start the full summary on the third line. The body should be no longer than 100 characters.
Then, tell Copilot to use this file by adding this setting in VS Code settings.json:
"github.copilot.chat.commitMessageGeneration.instructions": [
{
"file": ".copilot-commit-message-instructions.md"
}
]
🔧 Method 2: Entering Instructions Directly in VS Code Settings
Instead of using a file, you can specify the instructions directly in the settings:
"github.copilot.chat.commitMessageGeneration.instructions": [
{
"text": "Use conventional commit message format. Keep the first line under 50 characters."
}
]
Or combine both approaches:
"github.copilot.chat.commitMessageGeneration.instructions": [
{
"file": ".copilot-commit-message-instructions.md"
},
{
"text": "Use conventional commit message format."
}
]
While Copilot’s commit message generation is useful, it cannot yet include dynamic information (e.g., issue numbers, branch names) as highlighted in this GitHub issue.
For now, if you need dynamic elements in your commit messages, you’ll have to manually edit the suggestions before committing.
🔥 Example: Copilot-Generated Commit Messages
With the above configuration, Copilot might generate commit messages like this:
fix: resolve authentication issue
Updated token validation logic to prevent expired token errors.
This format improves readability and consistency across your commits.
⚡ Final Thoughts
GitHub Copilot’s commit message generation can save time and enforce consistency in your workflow. Whether you specify instructions in a file or directly in VS Code settings, you can guide Copilot to generate better commit messages.
🤖 Fun fact: This post got a little AI assistance—just like Copilot with commit messages! 😎