Skip to content
Back to skills

Safe Git Commit

ASecurity

Commit and push changes to a Git repository safely with active Git user confirmation and smart .gitignore hygiene. Checks and confirms the active Git user before any Git action, audits working tree changes, identifies files that should remain local (secrets, caches, local tests, dependencies, scratch files), updates .gitignore first instead of blindly staging everything, runs sanity checks/tests, crafts conventional commit messages, and pushes upstream cleanly. Use whenever the user asks to c...

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added October 19, 2026
ai-agentspythongoshellsqlnoderefactoringgitapidatabasedocumentation

Works with

  • vscode
  • terminal
  • cli
  • api

Security analysis

A100/100

Scanned November 25, 2026

npx -y skills add henryhyunwookim/agent-skills-and-policies --skill safe-git-commit --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Safe Git Commit?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Safe Git Commit
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/henryhyunwookim-safe-git-commit-agent-skills-and-policies/badge)](https://www.skillsdirectory.com/skills/henryhyunwookim-safe-git-commit-agent-skills-and-policies)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: safe-git-commit
description: Commit and push changes to a Git repository safely with active Git user confirmation and smart .gitignore hygiene. Checks and confirms the active Git user before any Git action, audits working tree changes, identifies files that should remain local (secrets, caches, local tests, dependencies, scratch files), updates .gitignore first instead of blindly staging everything, runs sanity checks/tests, crafts conventional commit messages, and pushes upstream cleanly. Use whenever the user asks to commit, push, or save changes to git.
---

# Safe Git Commit & Smart Hygiene Skill

Use this skill whenever committing and pushing changes to a Git repository. Rather than blindly executing `git add .` or staging test suites and local files, this workflow enforces strict safety gates: checking and confirming the active Git user before any Git action, auditing the working tree, identifying local-only artifacts (including local tests, test suites, secrets, caches, and scratch files), updating `.gitignore` first, verifying diffs, and authoring meaningful conventional commits.

---

## Safety Policy: Active Git User & What Must Stay Local

> [!IMPORTANT]
> **MANDATORY ACTIVE GIT USER CONFIRMATION & STRICT PER-TURN SCOPE**:
> - **Always Confirm Active Git User First**: Even when this skill is directly and explicitly invoked (such as via `/safe-git-commit`, `"commit and push"`, `"save changes to git"`), ALWAYS check the current active Git user (`user.name`, `user.email`, config origin, target remote, and active `gh` CLI account if installed) and **halt to ask for explicit user confirmation** before executing any mutating or remote Git action (`git rm --cached`, `git add`, `git commit`, `git pull --rebase`, `git push`).
> - Once the user confirms the active Git user (or updates it as requested), proceed cleanly through the rest of the commit and push workflow for that single turn.
> - **CRITICAL**: Commit/push authorization applies **EXCLUSIVELY to the current turn**. It NEVER carries over across conversation turns or to subsequent follow-up edits (e.g. "add section X", "update README"). Subsequent follow-up edits MUST remain uncommitted file modifications unless the user explicitly invokes `/safe-git-commit` again.


> [!CAUTION]
> **NEVER BLINDLY STAGE OR PUSH LOCAL ASSETS.**
> Untracked files and local development artifacts must be added to `.gitignore` before any staging command is executed.
> Specifically, local test suites (`tests/`, `test/`, `__tests__/`), test mocks, and ad-hoc test scripts MUST NOT be pushed to the remote repository unless the user explicitly requests committing tests.

### Local-Only Artifact Blacklist

The following categories must **always stay local** and be protected in `.gitignore`:

1. **Local Tests, Test Suites & Mocks**:
   - Directories: `tests/`, `test/`, `__tests__/`, `spec/`
   - Files & patterns: `*.test.*`, `*.spec.*`, `test_*.py`, `*_test.py`, `conftest.py`
   - Test data & databases: `test.db`, `*.sqlite3`, mock JSON/CSV test fixtures created for local verification
2. **Secrets, API Keys & Credentials**:
   - `.env`, `.env.local`, `.env.*.local`, `*.pem`, `*.key`, `*.token`, `credentials.json`, `token.json`, `service_account*.json`
3. **Virtual Environments & Dependencies**:
   - `.venv/`, `venv/`, `env/`, `ENV/`, `node_modules/`, `target/`, `vendor/`, `Pods/`
4. **Caches, Build Outputs & Coverage Reports**:
   - Python: `__pycache__/`, `*.py[cod]`, `.pytest_cache/`, `.mypy_cache/`, `.ruff_cache/`, `htmlcov/`, `.coverage`, `dist/`, `build/`, `*.egg-info/`
   - Web/Node: `.next/`, `.nuxt/`, `.turbo/`, `dist/`, `build/`, `out/`, `*.tsbuildinfo`
   - General: `.cache/`, `*.log`, `tmp/`, `temp/`
5. **OS & Editor Settings**:
   - Windows: `Thumbs.db`, `ehthumbs.db`, `Desktop.ini`, `$RECYCLE.BIN/`
   - macOS: `.DS_Store`, `.AppleDouble`, `.LSOverride`
   - IDEs: `.vscode/`, `.idea/`, `*.swp`, `*.swo`, `*~`
6. **Scratch & Ad-Hoc Scripts**:
   - `scratch/`, `tmp_*.py`, `debug_*.py`, exploratory notebooks (`*.ipynb` unless core deliverable), local dump logs

---

## Execution Workflow

```mermaid
flowchart TD
    U0["Step 1: Check Active Git User & Remote\n(git config user.name/email, git remote -v, gh auth status)"] --> U1{"User Confirms\nActive Git User?"}
    U1 -->|Switch Requested| U2["Update Local Git User / gh Account\n& Re-Verify Identity"]
    U2 --> U1
    U1 -->|Confirmed| A["Step 2: git status -s & Tree Audit"]
    A --> B{"Contains Local-Only Files?\n(tests/, secrets, caches, scratch)"}
    B -->|Yes| C["Step 3: Add Patterns to .gitignore First"]
    C --> D{"Were Local Files Tracked Previously?"}
    D -->|Yes| E["Untrack via git rm --cached -r <path>"]
    D -->|No| F["Verify Ignored Status (git status --ignored)"]
    E --> F
    B -->|No| F
    F --> G["Step 4: Review Diffs (git diff) & Run Local Sanity Checks"]
    G --> H["Step 5: Selective Staging: Stage ONLY Production Code & Manifests\n(NEVER git add . blindly)"]
    H --> I["Step 6: Compose Conventional Commit Message & git commit"]
    I --> K["Step 7: Sync Remote (git pull --rebase / git push)"]
    K --> L["Post-Push Verification (git status)"]
```

---

### Step 1: Check & Confirm Active Git User (Mandatory Gate)

Before running any mutating or remote Git action (`git rm --cached`, `git add`, `git commit`, `git pull --rebase`, `git push`):

1. **Inspect Active Git Identity & Remote Context (Read-Only)** using `the available terminal tool`:
   ```powershell
   git config --show-origin --get user.name
   git config --show-origin --get user.email
   git remote -v
   if (Get-Command gh -ErrorAction SilentlyContinue) { gh auth status }
   ```
   *(On POSIX shells, check `gh` with `command -v gh >/dev/null && gh auth status`. Never display or expose raw tokens or credentials.)*
2. **Flag Any Warnings**:
   - Warn prominently if `user.name` or `user.email` is unset/missing.
   - Highlight any apparent mismatch between the active Git `user.email`, active `gh` CLI account, and target repository remote owner/organization.
3. **Present & Wait for Explicit Confirmation**:
   - Display the detected active Git `user.name`, `user.email` (with config origin: local vs. global), target remote URL/branch, and active GitHub CLI account (if installed).
   - Ask the user explicitly whether to proceed with this active Git user or switch first.
   - **STOP and wait for user confirmation** before executing any Git staging, untracking, committing, or pushing commands.
4. **If the User Requests Switching**:
   - Update repository-local Git config (`git config --local user.name "<name>"`, `git config --local user.email "<email>"`) and/or GitHub CLI account (`gh auth switch --user <account>`) as instructed, re-verify the active identity, and proceed once confirmed.

---

### Step 2: Working Tree Audit & Local Artifact Classification

1. Run `git status` and `git status -s` using `the available terminal tool` to inspect all tracked, modified, and untracked files.
2. Check every untracked file and modified file against the **Local-Only Artifact Blacklist**.
3. If any file belongs to the blacklist (especially `tests/`, test files, `.env`, caches, or local logs), flag it immediately for inclusion in `.gitignore`.

---

### Step 3: Update `.gitignore` and Untrack Local Files

Before staging any files:

1. **Inspect `.gitignore`**:
   - Read `.gitignore` using `the available file reader`. If it does not exist, create it.
2. **Add Missing Patterns**:
   - Append patterns under clean, dedicated headers:
     ```gitignore
     # Local tests & test artifacts
     tests/
     test/
     __tests__/
     *.test.*
     *.spec.*

     # Caches and build outputs
     __pycache__/
     .pytest_cache/
     .coverage
     htmlcov/

     # Secrets and environment files
     .env
     *.pem
     *.key
     credentials.json
     token.json

     # Logs and temporary files
     *.log
     tmp/
     temp/
     ```
3. **Untrack Accidentally Committed Local Files**:
   - If any blacklisted file or folder (e.g., `tests/`, `.env`, caches) is already tracked in Git, remove it from the Git index without deleting the local file:
     ```powershell
     git rm -r --cached tests/
     ```
4. **Confirm Ignored Status**:
   - Run `git status --ignored` to confirm that blacklisted items now appear under `Ignored files:` and NOT under `Changes to be committed:` or `Untracked files:`.

---

### Step 4: Review Diffs & Run Sanity Checks

1. **Inspect Diffs**:
   - Run `git diff` on modified files.
   - Verify that:
     - No accidental secrets, private tokens, or hardcoded local paths exist.
     - Production code cleanly compiles/imports.
2. **Execute Local Sanity Checks**:
   - Run local tests (e.g., `pytest tests/`, `npm test`) to ensure code works properly locally.
   - Verify that running tests does not regenerate untracked cache files outside `.gitignore`.

---

### Step 5: Selective & Intentional Staging

> [!WARNING]
> **DO NOT USE `git add .` OR `git add -A` BLINDLY.**
> Blind staging risks adding untracked test files, scratch scripts, or temporary data.

Stage only the explicit production files, manifests, and documentation:
```powershell
git add .gitignore README.md requirements.txt src/
```
Verify the staged index with `git status` to ensure that **only** intended production files are staged.

---

### Step 6: Compose Conventional Commit Message

Formulate clear, descriptive commit messages adhering to Conventional Commits:

- **Format**:
  ```
  <type>(<optional scope>): <imperative summary>

  - Detailed bullet point explaining why and what changed
  - Additional context, breaking changes, or references
  ```
- **Allowed Types**:
  - `feat`: A new production feature or enhancement.
  - `fix`: A bug fix in production code.
  - `refactor`: Production code refactoring.
  - `docs`: Documentation updates.
  - `chore`: Maintenance, dependencies, tooling, or `.gitignore` hygiene.
- **Execution**:
  ```powershell
  git commit -m "<type>: <concise summary>" -m "- <detail bullet 1>`n- <detail bullet 2>"
  ```
  *(Note: Only execute after the active Git user has been confirmed in Step 1.)*


---

### Step 7: Push Upstream & Final Verification

1. **Check Remote and Upstream Tracking**:
   - Run `git branch -vv` to verify the current branch and upstream tracker.
   - Rebase if needed: `git pull --rebase origin <current-branch>`.
2. **Push Commit**:
   - `git push origin <current-branch>`.
3. **Verify Clean Tree**:
   - Run `git status` to verify `Your branch is up to date` and `working tree clean`.
   - Provide the user with:
     - The commit hash, verified author (`user.name <user.email>`), and summary.
     - Confirmation of files committed vs files protected in `.gitignore`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.