DEV Community

Cover image for πŸš€ Customizing GitHub Copilot & GitLens for AI-Assisted Commit Messages πŸ§ πŸ’‘
MD Ehsanul Haque Rizvy
MD Ehsanul Haque Rizvy

Posted on

πŸš€ Customizing GitHub Copilot & GitLens for AI-Assisted Commit Messages πŸ§ πŸ’‘

Commit messages are essential for maintaining a clean, understandable project history. With GitHub Copilot πŸ€– and GitLens πŸ”, you can automate commit message generation with AI assistance, ensuring they are concise, meaningful, and well-structured.

🎯 Why Automate Commit Messages?

Commit messages should be clear and concise πŸ“. They provide context for changes and enhance team collaboration. But writing good messages every time? Tedious! πŸ˜΅β€πŸ’«

This is where GitHub Copilot and GitLens step in! πŸš€ These AI-powered tools help automate commit message generation while following best practices βœ….

πŸ›  Tools You'll Need:

πŸ”Ή GitHub Copilot – Powered by OpenAI’s GPT-4, suggests and generates commit messages based on your changes.
πŸ”Ή GitLens – A powerful Git extension for Visual Studio Code, enhancing your Git workflow with AI-generated commit messages.

βš™οΈ Setting Up GitHub Copilot & GitLens

1️⃣ Install GitHub Copilot πŸ€–
1️⃣ Open VSCode.
2️⃣ Navigate to the Extensions view(Ctrl + Shift + X or Cmd + Shift + X).
3️⃣ Search for "GitHub Copilot" and install it.
4️⃣ Sign in with your GitHub account.

2️⃣ Install GitLens πŸ”
1️⃣ Open VSCode.
2️⃣ Go to the Extensions view.
3️⃣ Search for "GitLens" and install it.
4️⃣ GitLens will automatically integrate with your Git workflow in VSCode.

πŸ›  Configure Commit Message Generation ⚑️

3️⃣ Create .copilot-commit-message-instructions.md πŸ“œ
This file provides commit message rules for GitHub Copilot. Place it in the root of your project.

***πŸ“Œ Example Instructions:*

GitHub Copilot Commit Message Instructions πŸš€

General Guidelines:

βœ… Use the imperative mood (e.g., "Add feature" instead of "Added feature").

βœ… Be concise and clear – avoid overly detailed explanations.

βœ… Follow standard commit types:

  • feat: πŸš€ For new features
  • fix: πŸ› For bug fixes
  • refactor: πŸ”„ For restructuring code without behavior changes
  • style: 🎨 For cosmetic changes
  • perf: ⚑ For performance improvements
  • test: πŸ§ͺ For adding/updating tests

πŸ“Œ Examples:

  • feat(auth): add two-factor authentication πŸ”
  • fix(ui): correct button hover effect 🎨
  • refactor(api): optimize database queries πŸš€
  • style(css): update button styles πŸ’… **

4️⃣ Configuresettings.json βš™οΈ

"git.enableSmartCommit": true

πŸ” Test & Verify Commit Message Generation 🎯

1️⃣ Make a change (e.g., add a feature or fix a bug).
2️⃣ Open Source Control(Ctrl + Shift + G / Cmd + Shift + G).
3️⃣ Commit your changes – Copilot will suggest a commit message based on the changes.
4️⃣ Review & refine the message if necessary.

If commit messages don’t meet expectations, tweak .copilot-commit-message-instructions.md✍️.

πŸ›  Troubleshooting Tips πŸ”§

πŸ”Ή No commit messages? – Ensure .copilot-commit-message-instructions.md is in the root of your project.
πŸ”Ή Messages too verbose? – Simplify the instructions to focus on clarity and conciseness.
πŸ”Ή VSCode doesn’t suggest commits? – Restart VSCode and check Copilot authentication.

πŸš€ Conclusion

By integrating GitHub Copilot πŸ€– and GitLens πŸ”, you can automate commit messages, making them consistent and efficient. This saves time, reduces human error, and keeps your commit history clean & structured πŸ“œ.

Now, every commit tells a storyβ€”without the extra effort! πŸŽ―πŸš€

Top comments (0)