# AI Commit

> Generate AI-powered git commit messages with security scanning

Source: https://praison.ai/docs/cli/commit/
The `commit` command generates intelligent git commit messages based on your staged changes using AI, with built-in security scanning to prevent accidental exposure of sensitive data.

> **Info:** **Install requirement:** `praisonai commit` requires `pip install praisonai` (the full wrapper). On a standalone `pip install praisonai-code` install every `commit` subcommand exits `1` with `commit requires the full wrapper. Install the full wrapper: pip install praisonai` — a single-line hint, no Rich traceback ([PR #2854](https://github.com/MervinPraison/PraisonAI/pull/2854)).

## Quick Start

```bash
# Full auto mode: stage, security check, commit, and push
praisonai commit -a

# Interactive mode
git add .
praisonai commit
```

![Git Commit Helper](./commit-git-commit-helper.gif)

## Usage

### Full Auto Mode (Recommended)

```bash
praisonai commit -a
```

This single command will:
1. **Auto-stage** all changes (`git add -A`)
2. **Security scan** for sensitive content (API keys, passwords, secrets)
3. **Generate** AI commit message from diff
4. **Commit** with the generated message
5. **Push** to remote repository

**Expected Output:**
```
Auto-staging all changes...
Staged changes:
 src/main.py | 15 +++++++++------
 tests/test_main.py | 8 ++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)

Generating commit message...

Suggested commit message:
feat(main): add user authentication with JWT tokens

✅ Committed successfully!
✅ Pushed to remote!
```

> **Warning:** If sensitive content is detected in auto mode, the commit will be **automatically aborted** for safety. Use `--no-verify` to skip security checks (not recommended).

### Interactive Mode

```bash
praisonai commit
```

**Expected Output:**
```
Staged changes:
 src/main.py | 15 +++++++++------
 tests/test_main.py | 8 ++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)

Generating commit message...

Suggested commit message:
feat(main): add user authentication with JWT tokens

- Implement JWT token generation and validation
- Add login and logout endpoints
- Include unit tests for authentication flow

Options:
  [y] Use this message and commit
  [e] Edit the message
  [n] Cancel

Your choice [y/e/n]: 
```

### Commit and Push (Interactive)

```bash
praisonai commit --push
```

This will generate the commit message, commit the changes, and push to the remote repository after confirmation.

## Workflow

1. **Stage Changes**: Use `git add` to stage your changes
2. **Run Command**: Execute `praisonai commit`
3. **Review Message**: AI generates a commit message based on the diff
4. **Choose Action**:
   - `y` - Accept and commit
   - `e` - Edit the message in your default editor
   - `n` - Cancel

## Commit Message Format

The AI follows the [Conventional Commits](https://www.conventionalcommits.org/) specification:

```
<type>(<scope>): <short description>

<optional body with more details>
```

### Types

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

### Examples

```
feat(auth): add user authentication with JWT tokens

fix(api): resolve null pointer exception in user lookup

docs(readme): update installation instructions

refactor(database): optimize query performance for large datasets

test(auth): add unit tests for login flow
```

## Options

| Option | Description |
|--------|-------------|
| `-a`, `--auto` | Full auto mode: stage all, security check, commit, and push |
| `--push` | Automatically push after committing (interactive mode) |
| `--no-verify` | Skip security check (use with caution) |

## Security Scanning

The commit command includes built-in security scanning to prevent accidental exposure of sensitive data.

### Detected Patterns

  
### API Keys & Tokens

- API keys (`api_key`, `apikey`)
    - Secret keys (`secret_key`, `secretkey`)
    - Access tokens (`access_token`, `accesstoken`)
    - Auth tokens (`auth_token`, `authtoken`)
    - Client secrets (`client_secret`)

  
  
### Cloud Provider Credentials

- AWS Access Key IDs (`AKIA...`)
    - AWS Secret Access Keys
    - GitHub Personal Access Tokens (`ghp_...`)
    - GitHub OAuth Tokens (`gho_...`)
    - GitLab Personal Access Tokens (`glpat-...`)
    - Slack Tokens (`xox...`)

  
  
### Passwords & Private Keys

- Passwords (`password`, `passwd`, `pwd`)
    - Database passwords (`db_password`)
    - Private keys (PEM, RSA, DSA, EC, OPENSSH, PGP)

  
  
### Sensitive Files

- Environment files: `.env`, `.env.local`, `.env.production`, `.env.development`
    - SSH keys: `id_rsa`, `id_dsa`, `id_ecdsa`, `id_ed25519`
    - Certificates: `.pem`, `.key`, `.p12`, `.pfx`, `.jks`, `.keystore`
    - Credentials: `credentials`, `secrets.json`, `secrets.yaml`, `.htpasswd`, `.netrc`

### Security Warning Example

```
⚠️  SECURITY WARNING: Sensitive content detected!
  • API Key in diff: api_key = "sk-1234567890abcdefghij...
  • Sensitive File in config/.env: .env

Options:
  [c] Continue anyway (not recommended)
  [a] Abort commit
  [i] Ignore and add to .gitignore

Your choice [c/a/i]: 
```

### Auto Mode Behavior

In auto mode (`-a`), if sensitive content is detected:
- The commit is **automatically aborted**
- No changes are pushed
- You must fix the issue or use `--no-verify` to proceed

```bash
# Auto mode aborts on security issues
praisonai commit -a
# Output: Auto mode aborted due to security concerns. Use --no-verify to skip.

# Skip security check (not recommended)
praisonai commit -a --no-verify
```

## Requirements

- Git must be installed and available in PATH
- You must be in a git repository
- For interactive mode: changes must be staged with `git add`
- For auto mode (`-a`): changes will be auto-staged

## Error Handling

### No Staged Changes

```bash
$ praisonai commit
No staged changes. Use 'git add' to stage files first, or use -a/--auto.
```

**Solution:** Stage your changes with `git add .` or use `praisonai commit -a` for auto-staging

### Not in Git Repository

```bash
$ praisonai commit
ERROR: Not in a git repository
```

**Solution:** Navigate to a git repository or initialize one with `git init`

## Customization

### Using a Different Model

`praisonai commit` honours the same LLM-selection cascade as every other CLI command. The first match wins:

```bash
# 1. CLI flag — recommended, overrides everything else
praisonai commit --llm claude-3-5-sonnet-latest

# 2. MODEL_NAME env var — inherits your usual PraisonAI model
MODEL_NAME=claude-3-5-sonnet-latest praisonai commit

# 3. OPENAI_MODEL_NAME env var — still works for OpenAI users
OPENAI_MODEL_NAME=gpt-4o praisonai commit

# 4. Fallback — gpt-4o-mini when nothing is set
praisonai commit
```

> **Note:** Earlier releases read only `OPENAI_MODEL_NAME` for commit messages, silently ignoring `--llm` and `MODEL_NAME`. If your workflow pins `OPENAI_MODEL_NAME=gpt-4o-mini` for cheap commit messages, keep it — the fallback is unchanged. Otherwise `--llm` now works as expected.

### Git Identity Configuration

Configure custom git commit author for `praisonai commit` command.

#### Environment Variables

Set these in your shell configuration:

```bash
export PRAISONAI_GIT_USER_NAME="Your Name"
export PRAISONAI_GIT_USER_EMAIL="your.email@example.com"
```

#### GitHub Noreply Email

Use GitHub's noreply email to protect your personal email:

```bash
export PRAISONAI_GIT_USER_NAME="YourUsername"
export PRAISONAI_GIT_USER_EMAIL="YourUsername@users.noreply.github.com"
```

#### Verification

After setting, commits will show your identity:
```bash
praisonai commit -a
# Commits as: Your Name <your.email@example.com>
```

> **Info:** For detailed git identity configuration across all PraisonAI services, see [Git Identity Configuration](/cli/git-identity).

### Custom Editor

Set the `EDITOR` environment variable to use your preferred editor:

```bash
export EDITOR=vim
praisonai commit
# Choose 'e' to edit with vim
```

## Best Practices

  - **Review Before Accepting**: Always review the generated message before accepting
  - **Stage Related Changes**: Stage related changes together for better commit messages
  - **Small Commits**: Make small, focused commits for clearer messages
  - **Edit When Needed**: Use the edit option to refine the message

## Integration with Git Workflow

```bash
# Full auto workflow (recommended)
praisonai commit -a

# Interactive workflow
git add src/feature.py tests/test_feature.py
praisonai commit
git push

# Interactive with auto-push
git add .
praisonai commit --push
```

## Troubleshooting

| Issue | Solution |
|-------|----------|
| Empty commit message | Ensure changes are staged and diff is not empty |
| API error | Check your OpenAI API key is set |
| Editor not opening | Set the `EDITOR` environment variable |
| Push failed | Check remote repository access and authentication |
| Security warning in auto mode | Fix sensitive content or use `--no-verify` |
| Auto mode aborted | Remove sensitive files from staging or add to `.gitignore` |
| Commits show "PraisonAI" instead of my name | Set `PRAISONAI_GIT_USER_NAME` and `PRAISONAI_GIT_USER_EMAIL` env vars |

## Related

- [Git Identity Configuration](/cli/git-identity) - Configure commit author identity
- [CLI Overview](/cli/cli) - PraisonAI CLI documentation
- [Planning](/cli/planning) - AI planning mode
