Skip to content

Instantly share code, notes, and snippets.

@Xsir0
Last active January 22, 2026 12:10
Show Gist options
  • Select an option

  • Save Xsir0/a0a435f00fd45a7fb9a6454996b0d636 to your computer and use it in GitHub Desktop.

Select an option

Save Xsir0/a0a435f00fd45a7fb9a6454996b0d636 to your computer and use it in GitHub Desktop.
Error in user YAML: (<unknown>): did not find expected key while parsing a block mapping at line 1 column 1
---
description: Git commit helper (no-args = commit ALL changes automatically)
argument-hint: [MSG="<message>"] [FILES="<paths>"] [TYPE=<feat|fix|docs|refactor|test|chore>] [SCOPE="<scope>"] [RUN="<cmd>"] [NO_VERIFY=true]
---

You are running in a local repo. Create exactly ONE high-quality Git commit.

CRITICAL BEHAVIOR CHANGE (commit-all mode):

  • If the user invokes this command with NO arguments (i.e., $ARGUMENTS is empty AND all named inputs below are empty), then you MUST automatically stage and commit ALL current changes (including new/untracked files) without asking. Concretely: run git add -A, generate an appropriate commit message, then commit.

Safety rules (always):

  • Do NOT discard, reset, clean, stash, rebase, amend, or rewrite history.
  • Do NOT push. Only create a local commit.
  • If checks fail (whitespace check or $RUN), STOP and report; do not commit.

Inputs (may be empty):

  • $ARGUMENTS: all space-separated arguments after the command.
  • $FILES: space-separated paths to stage (quoted by the user when needed).
  • $MSG: commit message to use (may be empty).
  • $TYPE and $SCOPE: used to build a Conventional Commit subject if $MSG is empty.
  • $RUN: optional command to run before committing (tests/lint), e.g. RUN="npm test" or RUN="pnpm lint".
  • $NO_VERIFY: if "true", pass --no-verify to git commit.

Procedure:

  1. Confirm this is a Git repo and capture status.

    • Run: git rev-parse --show-toplevel
    • Run: git status -sb
    • Run: git status --porcelain=v1 If there are no changes (clean tree), stop and say: "Nothing to commit."
  2. Decide staging mode.

    2.1) Commit-all mode (NO ARGS):

    • Condition: $ARGUMENTS is empty AND $FILES/$MSG/$TYPE/$SCOPE/$RUN/$NO_VERIFY are all empty.
    • Action:
      • Stage everything:
        • Run: git add -A

    2.2) Selective mode (ARGS PRESENT):

    • Check currently staged changes:
      • Run: git diff --cached --name-status
    • If $FILES is provided (non-empty):
      • Stage ONLY those files:
        • Run: git add -- $FILES
    • Else if there are already staged changes:
      • Do NOT stage anything else. Proceed with the staged set.
    • Else (no staged changes and no $FILES):
      • Ask ONE short question before proceeding: "No files specified and nothing is staged. Stage all changes with 'git add -A' and commit?"
      • If user says yes:
        • Run: git add -A
      • If user says no:
        • Tell them to re-run with FILES="..." or stage changes manually, then stop.
  3. Show what is staged and ensure it is non-empty.

    • Run: git diff --cached --stat
    • Run: git diff --cached If staged diff is empty, stop and explain why.
  4. Run checks.

    • Always run whitespace check on staged diff:
      • Run: git diff --cached --check
      • If it reports problems, stop and paste the output; do not commit.
    • If $RUN is provided and non-empty:
      • Run exactly: $RUN
      • If it fails, stop and report the failure; do not commit.
  5. Prepare commit message.

    • If $MSG is provided and non-empty: use it exactly.
    • Else:
      • Build a Conventional Commit style subject:
        • If $TYPE is empty:
          • Infer best type from diff: feat/fix/docs/refactor/test/chore.
          • If changes are broad/mixed or look like a snapshot, default to: chore
        • If $SCOPE provided: SUBJECT = "$TYPE($SCOPE): " else SUBJECT = "$TYPE: "
      • Create a short body (2-6 bullets) summarizing the key changes (what/why).
      • Keep SUBJECT <= 72 chars when possible.
      • If there are breaking changes, include a "BREAKING CHANGE:" footer.
    • Ensure the message is accurate and grounded in the staged diff.
  6. Commit.

    • If $NO_VERIFY == "true", include --no-verify.
    • If you have a body, use: git commit -m "" -m "" else: git commit -m ""
  7. Show final result.

    • Run: git show --stat --oneline -1
    • Run: git status -sb

Output requirements:

  • Print the final commit subject line.
  • Print a short summary of which files were included (from git show --stat / staged names).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment