Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
345 changes: 345 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,345 @@
# git-ai

> AI-Powered Visual Git CLI for modern developers

[![CI](https://github.com/BeyteFlow/git-ai/actions/workflows/ci.yml/badge.svg)](https://github.com/BeyteFlow/git-ai/actions/workflows/ci.yml)
[![CodeQL](https://github.com/BeyteFlow/git-ai/actions/workflows/codeql.yml/badge.svg)](https://github.com/BeyteFlow/git-ai/actions/workflows/codeql.yml)
[![npm version](https://img.shields.io/npm/v/git-ai.svg)](https://www.npmjs.com/package/git-ai)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Node.js](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen)](https://nodejs.org/)

`git-ai` is a terminal-native CLI that brings AI into your everyday Git workflow. It generates meaningful commit messages from your staged diff, resolves merge conflicts automatically, and gives you an interactive TUI for browsing GitHub Pull Requests β€” all without leaving your terminal.

---

## Features

- **AI commit messages** β€” Analyze staged changes and generate conventional, context-aware commit messages via Google Gemini.
- **Merge conflict resolution** β€” Detect all conflicted files and apply AI-suggested resolutions in one command.
- **Interactive PR viewer** β€” Browse, filter, and inspect GitHub Pull Requests in a rich terminal UI built with [Ink](https://github.com/vadimdemedes/ink).
- **Guided setup** β€” A single `init` command walks you through connecting your API keys and preferences.
- **Secure config** β€” Credentials are stored in `~/.aigitrc` with `0600` permissions, never in your repo.
- **Type-safe configuration** β€” Config schema validated at runtime with [Zod](https://zod.dev/).

---

## Installation

### npm (recommended)

```bash
npm install -g git-ai
```

### From source

```bash
git clone https://github.com/BeyteFlow/git-ai.git
cd git-ai/git-ai
npm install
npm run build
npm install -g .
```

**Requirements:** Node.js `>= 20.0.0`

---

## Quick Start

```bash
# 1. Configure your API keys
ai-git init

# 2. Stage your changes as usual
git add .

# 3. Let AI write the commit message
ai-git commit
```

---

## Usage

### `ai-git init`

Run once to set up your Gemini API key and preferences. Saves config to `~/.aigitrc`.

```bash
ai-git init
```

You will be prompted for:

| Prompt | Description |
|--------|-------------|
| Gemini API Key | Your key from [Google AI Studio](https://aistudio.google.com/app/apikey) |
| Model name | Defaults to `gemini-1.5-flash` |

If a config already exists you can choose to **overwrite**, create a **backup**, or **cancel**.

---

### `ai-git commit`

Generates a commit message for your currently staged changes and lets you accept, edit, or reject it before committing.

```bash
git add src/feature.ts
ai-git commit
```

Example session:

```
πŸ€– Analyzing changes with Gemini...

✨ Suggested message: "feat(auth): add JWT refresh token rotation"

Choose [a]ccept, [e]dit, or [r]eject: a
βœ… Committed successfully!
```

- `a` / `accept` β€” Commit with the suggested message.
- `e` / `edit` β€” Manually type a replacement message.
- `r` / `reject` β€” Abort the commit.

Commit messages are validated against the following rules before being applied:

- Cannot be empty or whitespace-only.
- Must be 72 characters or fewer.
- Must not contain control characters.

---

### `ai-git prs`

Opens an interactive terminal UI for browsing GitHub Pull Requests in the current repository.

```bash
ai-git prs
```

Requires a `github.token` entry in your `~/.aigitrc` (see [Configuration](#configuration)).

---

### `ai-git resolve`

Detects all files with active merge conflicts and applies AI-generated resolutions to each one.

```bash
git merge feature-branch
ai-git resolve
```

Example output:

```
πŸ€– Resolving: src/utils/parser.ts...
βœ… Applied AI fix to src/utils/parser.ts

πŸŽ‰ Successfully resolved 1 file(s).
```

Review the applied changes with `git diff` before staging and committing.

---

## Command Reference

| Command | Description |
|---------|-------------|
| `ai-git init` | Interactive setup wizard for API keys and preferences |
| `ai-git commit` | Generate an AI commit message for staged changes |
| `ai-git prs` | Launch interactive GitHub PR browser |
| `ai-git resolve` | Auto-resolve merge conflicts using AI |
| `ai-git --version` | Print the current version |
| `ai-git --help` | Show help for all commands |

---

## Configuration

Configuration is stored in `~/.aigitrc` as a JSON file with `0600` permissions.

```jsonc
{
"ai": {
"provider": "gemini", // "gemini" | "openai"
"apiKey": "YOUR_API_KEY",
"model": "gemini-1.5-flash" // optional, defaults to gemini-1.5-flash
},
"github": {
"token": "ghp_..." // optional, required for `ai-git prs`
},
"git": {
"autoStage": false, // auto-run `git add -A` before committing
"messagePrefix": "" // optional prefix prepended to every message
},
"ui": {
"theme": "dark", // "dark" | "light" | "system"
"showIcons": true
}
}
```

Re-run `ai-git init` at any time to update your configuration.

---

## Examples

### Generate a commit after a bug fix

```bash
git add src/api/handler.ts
ai-git commit
# πŸ€– Analyzing changes with Gemini...
# ✨ Suggested message: "fix(api): handle null response from upstream service"
# Choose [a]ccept, [e]dit, or [r]eject: a
# βœ… Committed successfully!
```

### Recover from a messy merge

```bash
git merge origin/main
# CONFLICT (content): Merge conflict in src/config.ts
ai-git resolve
# πŸ€– Resolving: src/config.ts...
# βœ… Applied AI fix to src/config.ts
git add src/config.ts
git commit
```

### Review open PRs before merging

```bash
ai-git prs
# Opens an interactive TUI listing all open pull requests
```

---

## Project Structure

```
git-ai/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ index.ts # CLI entry point (Commander.js)
β”‚ β”œβ”€β”€ commands/
β”‚ β”‚ β”œβ”€β”€ CommitCommand.ts # AI commit message generation
β”‚ β”‚ β”œβ”€β”€ InitCommand.ts # Setup wizard
β”‚ β”‚ β”œβ”€β”€ ResolveCommand.ts # Merge conflict resolver
β”‚ β”‚ └── TreeCommand.ts # Repository tree viewer
β”‚ β”œβ”€β”€ cli/
β”‚ β”‚ └── pr-command.ts # GitHub PR TUI launcher
β”‚ β”œβ”€β”€ core/
β”‚ β”‚ └── GitService.ts # Git operations (simple-git wrapper)
β”‚ β”œβ”€β”€ services/
β”‚ β”‚ β”œβ”€β”€ AIService.ts # Google Gemini integration
β”‚ β”‚ β”œβ”€β”€ ConfigService.ts # Config load/save with Zod validation
β”‚ β”‚ β”œβ”€β”€ ConflictResolver.ts
β”‚ β”‚ └── GitHubService.ts # Octokit GitHub API client
β”‚ β”œβ”€β”€ ui/
β”‚ β”‚ β”œβ”€β”€ PRList.tsx # Ink/React TUI component
β”‚ β”‚ └── TreeUI.tsx
β”‚ └── utils/
β”‚ └── logger.ts # Pino structured logger
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
└── LICENSE
```

---

## Development Setup

```bash
# Clone the repository
git clone https://github.com/BeyteFlow/git-ai.git
cd git-ai/git-ai

# Install dependencies
npm install

# Run in development mode (no build step needed)
npm run dev -- commit
```

Available scripts:

| Script | Description |
|--------|-------------|
| `npm run dev` | Run from source with `tsx` (no compile step) |
| `npm run build` | Compile TypeScript to `dist/` |
| `npm run lint` | Type-check with `tsc --noEmit` |
| `npm test` | Run linter (type-check) |

---

## Testing

Type-checking acts as the current test gate:

```bash
npm test
```

To manually exercise a command during development:

```bash
# Run commit command without building first
npm run dev -- commit

# Run init command
npm run dev -- init
```

---

## Roadmap

- [ ] OpenAI / GPT-4o support (`provider: "openai"`)
- [ ] Conventional Commits format enforcement
- [ ] `ai-git log` β€” AI-summarized git log
- [ ] `ai-git review` β€” AI inline code review before push
- [ ] Plugin system for custom AI providers
- [ ] Shell completions (bash / zsh / fish)

---

## Contributing

Contributions are welcome! Please follow these steps:

1. **Fork** the repository and create a feature branch:
```bash
git checkout -b feat/your-feature
```
2. Make your changes, ensuring `npm test` passes.
3. Commit using [Conventional Commits](https://www.conventionalcommits.org/):
```bash
git commit -m "feat(commit): add --dry-run flag"
```
4. Open a Pull Request against `main` with a clear description.

Please open an issue first for major changes or new features to discuss the approach.

---

## License

[MIT](LICENSE) Β© 2026 [BeyteFlow](https://github.com/BeyteFlow)

---

## Acknowledgements

- [Google Generative AI](https://ai.google.dev/) β€” Gemini API powering AI features
- [Ink](https://github.com/vadimdemedes/ink) β€” React-based terminal UI framework
- [Commander.js](https://github.com/tj/commander.js/) β€” CLI argument parsing
- [simple-git](https://github.com/steveukx/git-js) β€” Fluent Git interface for Node.js
- [Zod](https://zod.dev/) β€” TypeScript-first schema validation
Loading