| title | Git Operation Rules |
|---|---|
| description | Strict protocols for standard Git operations (commits & pushes), mandating explicit user requests and forbidding auto-actions. |
| category | Git & Repository Management |
Before any Git commands are executed, the agent MUST perform the following pre-flight checks to ensure the environment is correctly configured.
-
Authenticate Services: The agent MUST verify authentication status for required services (e.g., GitHub CLI)
within the correct shell environment. If authentication is missing, the agent MUST guide the user through the login process.
# Example for GitHub CLI within a Nix shell nix-shell -p github-cli --run "gh auth status" # If the above fails, guide the user to run: nix-shell -p github-cli --run "gh auth login"
Fallback delegations (MANDATORY when the named tool / capability is unavailable). Skill URLs are SHA-pinned hosted-VCS permalinks against the
ai-agentsparent repository, per Markdown Generation Skill §4.2.8 (Cross-Repository / Submodule Isolation Links):ghnot installed: defer to the GitHub REST API Fallback skill §3 for the REST equivalent of everyghcommand referenced in this rule.git push/git fetchreturns 401 / 403: defer to the Git / GitHub Auth Fallback skill §2 to classify the error (wrong-identity cache vs missing scope vs needs-fork) before retrying.- Agent
run_in_terminaltool unavailable: route every command in this rule through Terminal Fallback via VS Code Tasks skill §3 (file-mediated output capture). Interactive flows (gh auth login,git credential-manager) MUST still be surfaced to the user as manual commands per that skill §4.4.
-
Verify Tool Permissions: The agent MUST ensure that all necessary build tools have execute permissions.
# Example for Gradle wrapper chmod +x gradlew
After ensuring the environment is valid, the agent's first action is to confirm its operational context.
-
Identify the Target Repository: The agent MUST determine the correct Git repository to operate within based on
the user's request and the file paths being discussed.
-
Handle Nested Repositories: If a user's request concerns changes within a nested repository (a sub-directory that
is its own Git project), the agent MUST change its working directory into that sub-directory before executing any
gitorghcommands. -
Clarify Ambiguity: If the workspace contains multiple repositories and the target is unclear, the agent must ask
the user for clarification before proceeding (e.g., "Which repository should I be working in?
project-a/orproject-b/?").
-
Always use git commands to detect unstaged and staged changes in the folder or repository specified by the user.
-
When asked to commit staged files, only consider files that are staged (use git diff --cached or git status --short).
-
Always respect the folder, repository, or submodule specified by the user. If not specified, use the workspace root
or known repositories.
-
If the folder is a submodule, follow all submodule commit and branch management rules (see git-submodule-rules.md).
-
Don't manually scan or assume file changes; always rely on git for authoritative status. This includes untracked
files not captured by
.gitignore, which require explicit user confirmation before staging. -
Workflow-First Priority: If changes involve CI/CD (workflows, scripts), fix and verify the logic FIRST before
committing.
-
Submodule Integrity:
-
Dangling Pointer Check: Before pushing changes that update a submodule, the agent MUST verify that the
referenced submodule commit exists in the remote submodule repository.
-
Canonical Ancestry: Ensure the new submodule pointer is a descendant of the codebase's previous submodule
pointer if a linear history is expected.
-
Atomic Construction: Before any commit operation, follow the
git-atomic-commit-construction-rules.md to group and arrange changes.
-
Explicit Request Required: Do NOT generate commit messages or execute
git commitunless the user explicitlyrequests it.
-
Authorization Trigger: The agent MUST NOT proceed with any commit until the user explicitly says "start".
Other commands like "commit" are insufficient.
-
No Auto-Commits: Never assume a task completion implies a commit. Always wait for instruction.
-
Commit Messages: When authorized, must strictly follow
git-commit-message-rules.md.
-
Status Check First: Always run
git statusbefore any fetch, pull, or push operation to understand the currentstate.
-
Remote Check: Use
git fetch --dry-runorgit ls-remoteto check for remote changes WITHOUT fetching. Requiresuser confirmation.
-
Fetch Protocol: Do NOT execute
git fetchwithout explicit user confirmation. -
Pull Protocol:
-
Timing: Pull BEFORE making commits, not after.
-
Explicit Confirmation: Always ask user before pulling.
-
Rebase Option:
git pull --rebaserequires separate explicit confirmation. -
Discover Default Branch: The agent MUST NOT assume the default branch name. It MUST be discovered
programmatically before any checkout or rebase operation.
# Discover remote branches to identify the default (e.g., 'master' or 'main') git branch -r
This is the mandatory workflow for updating a local branch against its remote counterpart.
-
Stash Uncommitted Changes: To prevent conflicts, stash any local modifications.
git stash
-
Fetch Remote Updates:
git fetch
-
Rebase onto Default Branch: Rebase the current working branch against its remote counterpart.
git rebase origin/<remote-tracking-branch>
-
Pop Stash: Re-apply the stashed changes.
git stash pop
-
Push Protocol:
-
Explicit Request Required: Do NOT execute
git pushunless the user explicitly requests it. -
No Auto-Pushes: Even if a commit is requested, do not chain a push command unless specifically told to "commit
and push".
-
Offer, Don't Execute: After commits, OFFER the user to push. Wait for explicit "yes" or "push" command.
-
Safety First (High-Risk Operations):
-
git reset: Strictly forbidden for synchronization or resolving conflicts. If unstaging is needed, usegit reset <file>. Hard resets require explicit user confirmation after explaining the data loss risk. -
git rebase: Requires explicit user confirmation.
When rebasing with unstaged changes, use git stash to temporarily save work.
-
Stash Before Rebase:
git stash push -m "Descriptive message for stash" git pull --rebase origin <branch>
-
Pop After Rebase:
git stash pop
-
Conflict Resolution: If
git stash popcreates conflicts, resolve them manually, then:git add <resolved-files> git stash drop # Remove the stash entry after manual resolution
-
List Stashes: View all stashed changes:
git stash list
Stashes are user-authored work-in-progress. They MUST be treated as destructive-to-remove and require explicit per-stash authorization before any operation that drops, pops-and-loses, clears, or expires them.
The following commands MUST NOT be issued by an AI agent unless the user has authorized them for the specific stash ref(s) in the same conversational turn:
git stash drop [<stash>]git stash pop [<stash>]—popdeletes the stash on success; treat as dropgit stash clear— destroys ALL stashesgit reflog expire --expire=... refs/stash— invisible destructiongit gc --prune=nowwhile stash refs exist and are unreachable from another ref
"Cleanup" instructions (e.g., "cleanup full", "tidy up", "remove backups") DO NOT implicitly include stash removal. Stash drops MUST be itemized and gated separately, even inside a multi-step cleanup batch.
Before requesting authorization to drop a stash:
- Inventory — list all stashes across the repository AND its initialized submodules with
git stash list(parent and each submodule). - Inspect — show the user
git stash show -p <stash>(or summarized stat) so they can decide whether the work is recoverable elsewhere. - Diff against current — if the stash overlaps existing committed/uncommitted work, run
git diff <stash>^1 -- <files>to surface any unique semantic content the stash would lose on drop. - Request authorization — present the verdict ("no unique content" / "unique content present") and STOP for the user's explicit per-stash decision.
A dropped stash remains as a dangling commit object until pruned (default ~14 days, governed by
gc.reflogExpireUnreachable). To recover:
# Capture the SHA from the drop output BEFORE losing the terminal scrollback
git stash store -m "<original or recovery message>" <dangling-sha>
git stash list # confirm restored at stash@{0}If the SHA was not captured, search the dangling commits:
git fsck --unreachable --no-reflogs | awk '/commit/ {print $3}' \
| xargs -I{} git log -1 --format="%H %s" {} | grep -i "WIP\|stash\|<known-message>"Equivalent authorization gates apply to:
- Backup branches (
backup/*,bk-*,pre-*) — seegit-history-refinement-rules.mdcleanup gates. - Reflog entries —
git reflog expire,git reflog delete. - Dangling commits reachable only via reflog —
git gc --prune=now,git prune.
For any of the above, follow the same Inventory → Inspect → Authorize → Act protocol as for stashes.