Skip to content

Hamza-Rafique/git-commit-gen

Repository files navigation

git-commit-gen 📝✨

A CLI tool to generate standardized Git commit messages with ease.

npm version License: MIT

Features

  • 🚀 Interactive prompt for commit messages
  • 🔍 Commitlint integration for validation
  • 🛡️ Husky hooks for automatic commit message validation
  • 📋 Smart staging area management
  • 🎨 Colorful terminal output with chalk
  • ⚡ Fast and lightweight
  • 🔧 Works with any Git repository
  • Conventional Commits standard compliance

Installation

npm install -g @hamzarafique964/git-commit-gen

For project-specific setup (recommended):

 # Install as dev dependency
npm install --save-dev @hamzarafique964/git-commit-gen

# Set up commitlint and husky (optional)
npx commitlint --install
npm install -g @hamzarafique964/git-commit-gen

Usage

Basic Usage

git-commit-gen

Advanced Usage with Staging

The tool automatically detects unstaged changes and lets you:

  • Stage all changes at once
  • Select specific files to stage
  • Skip staging if needed
  • Stage your changes:

Full Workflow Example

# Make some changes to your files
echo "console.log('new feature');" >> feature.js

# Run the commit wizard
git-commit-gen

# Follow the interactive prompts:
? Select commit type: (Use arrow keys)
❯ feat: A new feature
  fix: A bug fix 
  docs: Documentation changes
  chore: Maintenance tasks
  style: Code style changes
  refactor: Code refactoring
  test: Adding tests

? Enter commit message: add new authentication system

🔍 Validating commit message...
✓ Commit message validated!

📝 Generated: "feat: add new authentication system"
? Proceed with commit? Yes
✔ Committed successfully!

Commit Types Supported

  • feat - A new feature
  • fix - A bug fix
  • docs - Documentation changes
  • chore - Maintenance tasks
  • style - Code style changes (formatting, etc.)
  • refactor - Code refactoring
  • test - Adding or updating tests

Integration with Commitlint & Husky

The package includes built-in support for commit message validation:

Manual Validation

# Test a commit message
echo "feat: add new feature" | npx commitlint

Automatic Validation with Husky

When installed in a project, it sets up Husky hooks to automatically validate commit messages.

Configuration

Create a commitlint.config.js file in your project root:

module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [2, 'always', [
      'feat', 'fix', 'docs', 'chore', 'style', 'refactor', 'test'
    ]]
  }
};

Example Commit Messages

✅ Valid:

  • feat: add user authentication
  • fix: resolve login timeout issue
  • docs: update API documentation

❌ Invalid:

  • added new stuff (missing type)
  • fix: (missing description)
  • FEAT: add feature (uppercase type)

Troubleshooting

If you get Husky pre-commit errors:

# Add a test script to package.json
npm pkg set scripts.test="echo 'No tests'"

# Or skip hooks temporarily
git commit --no-verify

If commitlint is not installed:

npm install --save-dev @commitlint/cli @commitlint/config-conventional

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT © Hamza Rafique

About

A simple interactive CLI tool that helps you generate clear and consistent Git commit messages with ease.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published