DEV Community

Cover image for Automate Your Git Commits with AI - Introducing `git-ai-commit
syedharis14
syedharis14

Posted on

Automate Your Git Commits with AI - Introducing `git-ai-commit

Writing commit messages can be tedious, and maintaining consistency in commit logs is often overlooked. Thatโ€™s why I built git-ai-commit โ€“ an AI-powered CLI tool that generates meaningful, structured commit messages based on staged changes. ๐Ÿ“โœจ

๐ŸŽฏ Why git-ai-commit?

  • Saves Time โ€“ No need to think about commit messages manually!
  • Consistent Messages โ€“ Follows Conventional Commits format.
  • Multi-Language Support โ€“ Generate commit messages in English, French, Spanish, Urdu, Arabic, and more!
  • Auto-Commit โ€“ Directly commit without manual approval.
  • Usage Tracking โ€“ View CLI usage statistics.
  • Smart AI Processing โ€“ Analyzes git diff and suggests precise messages.

๐Ÿ› ๏ธ Installation

Install git-ai-commit globally using NPM:

npm install -g @syedharis14/git-ai-commit
Enter fullscreen mode Exit fullscreen mode

๐Ÿš€ How to Use It

1๏ธโƒฃ Generate an AI-powered commit message

git-ai-commit generate
Enter fullscreen mode Exit fullscreen mode

2๏ธโƒฃ Auto-commit using AI-generated message

git-ai-commit generate --auto-commit
Enter fullscreen mode Exit fullscreen mode

3๏ธโƒฃ Copy commit message to clipboard

git-ai-commit generate --copy
Enter fullscreen mode Exit fullscreen mode

4๏ธโƒฃ Generate message in a specific language

git-ai-commit generate --lang fr
Enter fullscreen mode Exit fullscreen mode

5๏ธโƒฃ View usage statistics

git-ai-commit stats
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” How It Works

  1. git-ai-commit fetches the staged git diff.
  2. It sends the diff to OpenAIโ€™s API for analysis.
  3. AI generates a Conventional Commit-style message.
  4. The message is displayed, copied, or committed automatically.

๐Ÿ“ฆ Example Commit Message

Before:

git add .
git-ai-commit generate
Enter fullscreen mode Exit fullscreen mode

AI Response:

feat(auth): add OAuth2 login endpoint
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“Œ Configuration

Create a .git-ai-commitrc in your project to customize behavior:

{
  "model": "gpt-4o",
  "maxLines": 100,
  "autoCommit": false,
  "copy": false,
  "lang": "en",
  "analytics": true
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿš€ Open Source & Contribution

This project is open-source and Iโ€™d love your contributions! Feel free to star โญ the repo, open issues, or contribute!

๐Ÿ”— GitHub Repository

๐Ÿ”— NPM Package


What do you think about git-ai-commit? Would this help improve your workflow? Let me know in the comments! ๐Ÿš€

Top comments (0)