iGit Documentation

website·Indexed 31 days ago

https://igit.erguotou.me

An AI-powered tool for generating commit messages that follow conventional commits. Features include an AI commit generator, Git hooks integration, and configuration via .config/igit.yaml.

Tokens
1.6K
Snippets
14
Records
17
Agent score
49%

What's inside iGit

  1. Overview of iGit AI-Powered Commit Messages

    iGit is a tool that automatically generates commit messages following the Conventional Commits specification to ensure a clear and professional commit history.
  2. Generate commit messages using iGit AI

    iGit uses AI to analyze files in the Git staged area (additions, deletions, modifications, and context) to generate commit messages that follow the Conventional Commits specification. The AI automatically determines the commit type (e.g., feat, fix, docs) based on the code changes.
    # Generate a commit message and wait for user confirmation
    igit commit
    
    # Generate a commit message and commit immediately without confirmation
    igit commit -y
    
    # Generate the message only (dry-run) without performing the git commit
    igit commit -d
  3. Install and initialize iGit in a project

    To set up iGit, install the CLI package, initialize the project configuration, and install the necessary Git hooks. After initialization, you can customize the project settings in the generated .config/igit.yaml file, which includes schema hints for easier editing.
    # 1. Install the CLI
    npm install @doremijs/igit-cli
    
    # 2. Initialize iGit configuration
    npx igit init
    
    # 3. Install Git Hooks
    npx igit install
  4. Manage Git Hook installation and execution

    iGit hooks behave as follows:

    • Commands run sequentially; failure of one stops the chain.
    • In CI environments, hook installation is skipped automatically.
    • To manually skip hook installation, use the --skip-install flag.
  5. Initialize and locate the iGit configuration file

    iGit uses a YAML configuration file located at .config/igit.yaml. You can generate a default configuration file automatically by running the igit init command.
    igit init
  6. Optimize AI commit message quality

    To ensure the AI generates accurate and high-quality commit messages, follow these best practices:

    1. Keep Changes Focused: Only include related changes in a single commit so the AI can better understand the intent.
    2. Use the Staged Area: Ensure only the files intended for the commit are staged before running the command.
    3. Review Messages: Always review the AI-generated message before finalizing the commit to ensure it reflects the business context accurately.
    # Correct workflow: stage specific files then commit
    git add <files>
    igit commit
  7. Configure Commit Message validation

    Manage how commit messages are validated and formatted using the commit_msg configuration options. Available options include enabling validation, defining a list of valid commit types, and automatically prepending emojis to messages.
    commit_msg:
      enabled: true
      validTypes: ["feat", "fix", "docs"]
      prependEmoji: true
  8. Configure Staged Hooks for file-specific processing

    Use staged_hooks to run specific commands based on file patterns. File matching is handled by fast-glob (Rust ecosystem). Define patterns as keys in the rules object and provide a list of commands to run against matching files.
    staged_hooks:
      enabled: true
      rules:
        "**/*.{js,ts}":
          - eslint --fix
          - prettier --write
        "**/*.{css,less,scss}":
          - stylelint --fix
  9. Configure Staged Hooks for file-specific linting and formatting

    Staged hooks execute commands specifically on modified files before a commit. This is typically used for code checking and formatting. After these commands execute, iGit automatically re-adds the modified files to the git staging area.
    staged_hooks:
      enabled: true
      rules:
        "**/*.{js,ts}":
          - eslint --fix
        "**/*.{css,scss}":
          - stylelint --fix
  10. Generate AI-powered commit messages with iGit

    iGit can automatically summarize code changes and generate commit messages that follow the Conventional Commits specification. This requires AI-related configuration to be added to the .config/igit.yaml file before execution.
    git add .
    npx igit commit -y
  11. Implement a code checking workflow with iGit hooks

    A recommended best practice for code quality is to use staged_hooks for fast linting/formatting of changed files and pre-push hooks for heavier tasks like test coverage and production builds.
    hooks:
      enabled: true
      hooks:
        pre-push:
          - npm run test:coverage
          - npm run build
    
    staged_hooks:
      enabled: true
      rules:
        '**/*.{css,scss,less,styl,stylus}': stylelint --fix
        '**/*.{js,jsx,ts,tsx}': biome check --write
  12. Configure AI features and OpenAI integration

    Enable AI capabilities by configuring the ai section. To secure your API key, it is recommended to use the OPENAI_API_KEY environment variable instead of writing the key directly in the igit.yaml file, or ensure the config file is excluded from git version control.
    ai:
      enabled: true
      baseUrl: https://api.openai.com
      apiKey: your-api-key # Use OPENAI_API_KEY env var instead
      model: gpt-3.5-turbo
      respondIn: English