DEV Community

Okinea Dev
Okinea Dev

Posted on • Originally published at okineadev.Medium on

🤖 Use AI to speed up writing commit messages (bonus: custom prompt for improved generation)

Creating commits is an integral part of working with Git , and it’s equally important to create understandable commit messages, but we (most likely) are too lazy to describe them in detail and clearly, but we don’t want our commit history to look something like this: “update this “, “fix”, “fix”, “wjkwefjke”, “” and etc.

GitHub Copilot comes to the rescue! — the GitHub Copilot extension for VS Code has a function for generating commit messages

📋 Requirements

  1. GitHub Copilot access on your *GitHub * account.
  2. VSCode with GitHub Copilot enabled.

Commit menu in VS Code
Commit menu in VS Code

There is an icon with sparks (✨) on the right of the commit input field, this is the button for generating a commit message

When we click on the commit generation button — the AI ​​will generate a message based on the diff of the changed files, you can see the result below 👇

Copilot wrote the following commit message: _fix: 🩹 update uninstall command to handle optional PREFIX variable_ and he wrote it correctly because I really fixed the uninstall command

This can really save you time, you don’t have to waste your time writing commit messages anymore, let Copilot do it for you 😉

🎁 Bonus: Custom prompt for improved commit message generation

I made a custom prompt for Copilot with commit generation rules, you can apply it with these steps:

  1. Go to vscode://settings/github.copilot.chat.commitMessageGeneration.instructions or type this in VS Code settings : _github.copilot.chat.commitMessageGeneration.instructions_

Visual Studio Code settings menu
Visual Studio Code settings menu

  1. Click “ Edit in settings.json

  2. Copy and paste this into settings.json :

"github.copilot.chat.commitMessageGeneration.instructions": [
  {
    "text": "Follow the **Conventional Commits** format strictly. Use the structure below:\n\n```

\n<type>[optional scope]: <gitmoji> <description>\n\n<detailed body>\n

```\n\n## Guidelines:\n\n1. **Type and Scope** : Choose a commit type (e.g., `feat`, `fix`) and an optional scope to describe the affected module or feature.\n2. **Gitmoji** : Include a relevant `gitmoji` that **best** represents the nature of the change.\n3. **Description** : Write a **concise** and **informative** description in the header. Use **backticks** if referencing code or specific terms.\n4. **Body** : For additional details, use a well-structured body section:\n- Use bullet points (`*`) for clarity.\n- Always clearly describe the motivation, context, or technical details behind the change if applicable.\n\nCommit messages should be **clear** , **informative** , and **professional** , aiding readability and project tracking."
  }
]
Enter fullscreen mode Exit fullscreen mode

Editing the Visual Studio Code settings file
Editing the Visual Studio Code settings file

This prompt defines the format of commit messages according to Conventional Commits with the addition of emoji (gitmoji). It consists of the following elements:

  1. Type and Scope : Specify the commit type (eg _feat_, _fix_) and, if applicable, the scope describing the module or functionality.
  2. Gitmoji : Added the appropriate gitmoji that best represents the changes.
  3. Description : Concise and informative title section, using backticks to refer to code or terms.
  4. Commit Body : More detailed information organized as a bulleted list describing the motivation, context, or technical details of the changes.

The goal is to make commits clear, understandable, and professional to improve project change tracking.

Done! Now that you’ve applied a custom prompt to generate commits, let’s take a look at the new output:


fix: 🩹 update uninstall command to handle optional PREFIX variable

* Adjusted the uninstall command in `README.md` to use `${PREFIX:-/usr}` for better flexibility.
* This change allows the command to default to `/usr` if the PREFIX variable is not set.
Enter fullscreen mode Exit fullscreen mode

As you can see, it now writes a detailed commit description and wraps filenames and code in backticks ( `` )

📝 Conclusion:

  • AI can significantly speed up routine tasks, including writing commit messages
  • Quality prompt — quality messages
  • Trust but check — check what the AI ​​wrote and correct it if it was wrong

Happy coding! 😄

Top comments (0)