---
name: git-agent
description: Auto-add, commit, and push all changes in the current working directory
disable-model-invocation: true
allowed-tools: Bash, Read, Glob, Grep
argument-hint: [optional commit message]
---

# Git Agent — Auto-Commit Skill

Automatically stage, commit, and push all changes in the current working directory.

## Context (injected at runtime)

- Current branch: !`git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "NOT A GIT REPO"`
- Repo root: !`git rev-parse --show-toplevel 2>/dev/null || echo "N/A"`
- Changed files (unstaged): !`git diff --name-only 2>/dev/null`
- Untracked files: !`git ls-files --others --exclude-standard 2>/dev/null`
- Staged files: !`git diff --cached --name-only 2>/dev/null`

## Instructions

When invoked, follow these steps exactly:

### Step 1 — Verify git repo
- If the current directory is NOT inside a git repo, initialize one:
  - Run `git init && git checkout -b main`
  - Create a basic `.gitignore` (Python/Node defaults)
  - Make an initial commit with the `.gitignore`

### Step 2 — Assess changes
- Run `git status` to see the full picture
- Run `git diff --stat` for a summary of modifications
- If there are NO changes at all (nothing untracked, modified, or staged), tell the user "No changes to commit" and stop

### Step 3 — Stage changes
- Run `git add -A` to stage everything

### Step 4 — Generate commit message
- If the user provided an argument (`$ARGUMENTS`), use that as the commit message
- Otherwise, generate a descriptive message based on what changed:
  - Look at the list of changed files and their types
  - Use conventional commit style: `feat:`, `fix:`, `chore:`, `refactor:`, `docs:`, `style:`, `test:`
  - Keep the subject line under 72 characters
  - Add a body listing the key changes if there are more than 3 files
  - Examples:
    - `feat: add user authentication module`
    - `chore: update dependencies and config files`
    - `refactor: restructure project layout (12 files moved)`

### Step 5 — Commit
- Run `git commit` with the generated message
- Use a HEREDOC format for multi-line messages:
  ```
  git commit -m "$(cat <<'EOF'
  subject line

  body here
  EOF
  )"
  ```

### Step 6 — Push
- Check if a remote is configured: `git remote -v`
- If a remote exists, push to it: `git push -u origin <current-branch>`
- If no remote exists, tell the user no remote is configured and show them how to add one:
  - `git remote add origin <url>`
  - Then they can re-run `/git-agent` to push

### Step 7 — Report
- Show the user:
  - The commit hash (short) and message
  - Number of files changed
  - The branch name
  - Whether the push succeeded or failed (and why)

## Rules
- NEVER force push
- NEVER use `--no-verify`
- Do NOT commit files that look like secrets (`.env`, `credentials.*`, `*.pem`, `*.key`). Warn the user if these exist
- If a pre-commit hook fails, show the error and stop — do not retry or bypass
