Git Product home page Git Product logo

git-gen's Introduction

🧩 Git-Gen: Automated Git Commit Message Generator

Overview

git-gen is a bash script that acts as a Git plugin to automate the generation of commit messages. It uses Anthropic's Claude model to analyze the changes in your Git repository and suggests a concise, informative commit message. The script also includes functionality to automatically prepend a Jira ticket ID to the commit message if it's present in the branch name.

Features

  • Automatic Commit Message Generation: Leverages Claude to generate commit messages based on the changes made.
  • Jira Ticket ID Detection: Automatically detects and prepends Jira ticket ID from the branch name to the commit message.
  • Editable Commit Messages: Offers the option to edit the generated commit message before committing.

Installation

  1. Clone the Repository:
    git clone https://github.com/yarlson/git-gen.git
  2. Make the Script Executable: Navigate to the script's directory and run:
    chmod +x git-gen
  3. Add to PATH: For macOS/Linux, you can move the script to /usr/local/bin or another directory in your PATH:
    mv git-gen /usr/local/bin

Usage

Once installed, you can use git-gen within any Git repository:

git gen

The script will perform the following actions:

  • Analyze the current Git repository for changes.
  • Generate a commit message using Anthropic's Claude.- Prompt you to accept (y), reject (n), or edit (e) the generated message.
  • If the branch name contains a Jira ticket ID (like DXP-123), it will prepend this ID to your commit message.
  • Commit the changes with the generated or modified commit message.

Requirements

  • jq: A lightweight and flexible command-line JSON processor.
  • curl: A tool to transfer data from or to a server.
  • git: Version control system.
  • An active Anthropic API key set in your environment as ANTHROPIC_API_KEY.

Configuration and Environment Variables

ANTHROPIC_API_KEY

git-gen requires an Anthropic API key to generate commit messages using Claude. You need to set this key as an environment variable named ANTHROPIC_API_KEY. There are two common methods to do this:

  1. Exporting Temporarily: You can export the API key in your current shell session. This method is temporary, and the API key will need to be re-exported in each new shell session.

    export ANTHROPIC_API_KEY='your_api_key_here'
  2. Adding to Shell Configuration: For convenience, you might want to add the API key to your shell configuration file (like .bashrc or .zshrc). This method makes the API key persistently available in all future shell sessions.

    echo 'export ANTHROPIC_API_KEY="your_api_key_here"' >> ~/.bashrc
    # or
    echo 'export ANTHROPIC_API_KEY="your_api_key_here"' >> ~/.zshrc

    After adding it, reload your shell configuration with source ~/.bashrc or source ~/.zshrc, or simply restart your terminal.

    Note: While adding the API key to your shell configuration file is convenient, it may be considered less secure, especially on shared systems. It is important to understand the security implications of storing sensitive information like API keys in configuration files.

Customizing the Script

You can further customize the behavior of git-gen by editing the script. For example, you might want to change the text editor used for editing commit messages or adjust the regular expression used for Jira ticket detection.

Contributing

Contributions to git-gen are welcome! Please feel free to submit pull requests or raise issues on the repository.

License

git-gen is licensed under the MIT License. See LICENSE.md for more information.

Disclaimer

This script uses the Anthropic API to generate commit messages. Please ensure you comply with Anthropic's use case policies and have a valid API key.

git-gen's People

Contributors

yarlson avatar

Stargazers

 avatar Szymon Chudy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.