Core Git
core.git
Protects against destructive git commands that can lose uncommitted work, rewrite history, or destroy stashes
- 28blocking rules
- 7safe patterns
- 7Critical
- 18High
- 3Medium
Always on. Core packs can’t be removed from evaluation, though each rule’s mode can be changed in [policy.rules].
Evaluated when a command contains git.
Recorded verdicts
git reset --hard HEAD~3Blockedcore.git:reset-hardgit reset --hard origin/mainBlockedcore.git:reset-hardgit checkout -- .Blockedcore.git:checkout-discardgit restore src/Blockedcore.git:restore-worktreegit clean -fdxBlockedcore.git:clean-forcegit push --force origin mainBlockedcore.git:push-force-longgit stash clearBlockedcore.git:stash-cleargit branch -D feature/paymentsBlockedcore.git:branch-force-deletesudo env git reset --hardBlockedcore.git:reset-hard/usr/bin/git reset --hardBlockedcore.git:reset-hardgit -C ./app reset --hardBlockedcore.git:reset-hardbash -c 'git reset --hard'Blockedcore.git:reset-hard
Blocking rules
Each rule ID is core.git:<name>. Use it in allowlists and [policy.rules].
Criticalclean-forcegit clean -f/--force removes untracked files permanently. Review with 'git clean -n' first.
Explanation
git clean -f permanently deletes untracked files from your working directory. These are files that have never been committed to git, so they cannot be recovered from git history. If you haven't backed them up elsewhere, they are gone forever. Common dangerous combinations: - git clean -fd: Also removes untracked directories - git clean -xf: Also removes ignored files (build artifacts, .env, etc.) Safer alternatives: - git clean -n: Dry-run, shows what would be deleted - git clean -i: Interactive mode, choose what to delete ALWAYS preview first: git clean -n -d
Criticalpush-force-longForce push can destroy remote history. Use --force-with-lease if necessary.
Explanation
git push --force overwrites remote history with your local history. This can permanently destroy commits that others have already pulled, causing data loss for your entire team. Collaborators may lose work, and recovering requires manual intervention from everyone affected. What can go wrong: - Commits others pushed are deleted from remote - Team members get diverged histories - CI/CD pipelines may reference deleted commits Safer alternative: - git push --force-with-lease: Only forces if remote matches your last fetch Check remote state first: git fetch && git log origin/<branch>..HEAD
Criticalpush-force-refspecA '+' refspec force-pushes that ref and can destroy remote history. Use --force-with-lease if necessary.
Explanation
In `git push <remote> +<ref>`, the leading `+` forces that one update exactly as --force would, overwriting remote history with your local history. Commits others already pushed to that ref are discarded from the remote. Safer alternative: - git push --force-with-lease <remote> <ref>: only forces if the remote still matches what you last fetched Check remote state first: git fetch && git log origin/<branch>..HEAD
Criticalpush-force-shortForce push (-f) can destroy remote history. Use --force-with-lease if necessary.
Explanation
git push -f (short for --force) overwrites remote history with your local history. This can permanently destroy commits that others have already pulled, causing data loss for your entire team. What can go wrong: - Commits others pushed are deleted from remote - Team members get diverged histories - CI/CD pipelines may reference deleted commits Safer alternative: - git push --force-with-lease: Only forces if remote matches your last fetch Check remote state first: git fetch && git log origin/<branch>..HEAD
Criticalread-tree-resetgit read-tree --reset -u overwrites the working tree like git reset --hard, destroying uncommitted changes.
Explanation
git read-tree --reset -u is the plumbing form of git reset --hard. It replaces the index with the given tree, discarding staged and unmerged entries, and -u then rewrites the working tree to match, overwriting every uncommitted modification to tracked files. Those changes were never committed, so they cannot be recovered. Safer alternatives: - git stash: save the changes first, restore later with 'git stash pop' - git read-tree -m -u <tree>: a merge that refuses to overwrite local changes - git status / git diff: see exactly what would be discarded
Criticalreset-hardgit reset --hard destroys uncommitted changes. Use 'git stash' first.
Explanation
git reset --hard discards ALL uncommitted changes in your working directory AND staging area. This is one of the most dangerous git commands because changes that were never committed cannot be recovered by any means. What gets destroyed: - All modified files revert to the target commit - All staged changes are lost - Untracked files remain (use git clean to remove those) Safer alternatives: - git reset --soft <ref>: Move HEAD but keep all changes staged - git reset --mixed <ref>: Move HEAD, unstage changes, keep working dir (default) - git stash: Save changes before resetting Preview what would be lost: git status && git diff
Criticalstash-cleargit stash clear permanently deletes ALL stashed changes.
Explanation
git stash clear removes ALL stash entries at once. Unlike git stash drop, which removes one at a time, this command wipes your entire stash list. All stashed changes become unreferenced and are very difficult to recover. What gets destroyed: - All entries in 'git stash list' are removed - Multiple sets of saved work-in-progress may be lost Safer alternatives: - git stash drop stash@{n}: Remove one specific stash at a time - git stash list: Review what would be lost first - git stash show stash@{n}: Inspect each stash before deciding Recovery (difficult, not guaranteed): git fsck --unreachable | grep commit
Highbranch-deletegit branch deletion requires explicit user approval.
Explanation
git branch -d (or --delete) removes a branch reference. Git refuses when it does not consider the branch merged into its upstream or HEAD, but a merged deletion still discards the branch name, its tracking configuration, and the convenient reflog reference. The user may intentionally need any of those, so agents must not delete a branch without explicit approval. This rule covers only the merge-checked form. -D, --delete --force, -f, -M and -C are reported as branch-force-delete. To let agents delete merged branches after review while still refusing the forced forms, set [policy.rules] "core.git:branch-delete" = "ask". Review without changing refs: - git branch -vv: Show branch tips and upstream tracking state - git branch --merged / --no-merged: Review Git's merge classification Recovery if deletion already happened: git reflog # Find the commit hash while it is still retained git branch <branch> <commit-hash>
Highbranch-dynamic-tokenA dynamic shell expansion in this git branch command can expand into a deletion or forced ref update. Quote the branch name or add `--` to make it a literal creation.
Explanation
An unquoted command substitution or variable in a git branch invocation is expanded and field-split by the shell before git parses it, so its output can inject `-D`, `-f`, `-M`, or `-C` and turn a branch creation into a deletion or forced ref update. dcg cannot statically bound the expansion's output. The reliable fix is to resolve the dynamic value first and rerun the command with the literal branch name. For a branch *creation*, these spellings are safe without any exception: - Quote the name so it stays one word: git branch "backup-$(date +%s)" - End option parsing first: git branch -- backup-$(date +%s) Both guarantee the expansion cannot become a flag. They do not unlock a command that already carries a literal deletion/force flag (`-D`, `-d`, `-f`, `-M`, `-C`) — branch deletion stays gated on its own merits.
Highbranch-force-deletegit branch deletion or forced ref updates require explicit user approval.
Explanation
git branch -D (--delete --force) removes a branch reference without Git's merge check, so commits reachable only from that branch are left to the reflog and garbage collection. The -f/--force forms can also move an existing branch reference away from commits, and the -M and -C shorthands force-overwrite an existing rename/copy target. Agents must not cross these user-intent boundaries without explicit approval. The merge-checked deletion (-d / --delete without force) is reported as core.git:branch-delete when dcg can parse the command; a command it cannot parse is reported here. A [policy.rules] or allowlist entry for this rule also covers core.git:branch-delete unless that rule has its own entry. Review without changing refs: - git branch -vv: Show branch tips and upstream tracking state - git branch --merged / --no-merged: Review Git's merge classification - git log --oneline --decorate <branch>: Inspect the branch history Recovery if deletion already happened: git reflog # Find the commit hash while it is still retained git branch <branch> <commit-hash>
Highcheckout-discardgit checkout -- discards uncommitted changes permanently. Use 'git stash' first.
Explanation
git checkout -- <path> discards all uncommitted changes to the specified files in your working directory. These changes are permanently lost - they cannot be recovered because they were never committed. Safer alternatives: - git stash: Save changes temporarily, restore later with 'git stash pop' - git diff <path>: Review what would be lost before discarding Preview changes first: git diff -- <path> Recovering from a failed `git pull --rebase`? Run `dcg rebase-recover` in this repo, then retry the command on its own line (a leading `cd <repo> &&` is fine; nothing else may share the line). This issues a short-lived, single-shot permit that unblocks this rule only. A rebase already in progress (`.git/rebase-merge/` or `.git/rebase-apply/` present) auto-allows the same rule without a permit.
Highcheckout-discard-cwdgit checkout . discards all uncommitted changes in the path. Use 'git stash' first.
Explanation
git checkout . (or git checkout <ref> .) overwrites the working tree from the index or a commit, discarding every uncommitted change under the current directory. The changes were never committed, so they cannot be recovered. Safer alternatives: - git stash: save the changes first, restore later with 'git stash pop' - git diff: review exactly what would be discarded - git checkout <ref> -- <specific-file>: limit the overwrite to reviewed files
Highcheckout-forcegit checkout -f/--force discards all uncommitted changes to tracked files. Use 'git stash' first.
Explanation
git checkout --force switches branches (or rewrites paths) even when that overwrites local modifications, and those modifications are discarded. They were never committed, so they cannot be recovered — the same outcome as git reset --hard. Safer alternatives: - git stash: save the changes, switch, then 'git stash pop' - git worktree add ../other <branch>: check the branch out alongside - git status / git diff: see exactly what the force would discard
Highcheckout-ref-discardgit checkout <ref> -- <path> overwrites working tree. Use 'git stash' first.
Explanation
git checkout <ref> -- <path> replaces your working tree files with versions from another commit or branch. Any uncommitted changes to those files are permanently lost - they cannot be recovered. Safer alternatives: - git stash: Save changes first, then checkout, then restore with 'git stash pop' - git show <ref>:<path>: View the file content without overwriting. View only — redirecting the output back onto <path> (`git show <ref>:<path> > <path>`) reaches the exact overwrite this rule denies. To capture the content, redirect to a NEW file: `git show <ref>:<path> > <path>.from-ref` Preview what would change: git diff HEAD <ref> -- <path>
Highfilter-branchgit filter-branch rewrites repository history and can permanently drop commits. Back up the refs first.
Explanation
git filter-branch rewrites every commit in the selected range, changing their hashes and, with the wrong filter, silently dropping commits or files. The original commits survive only in the reflog until it expires or is pruned. Safer alternatives: - Back up first: git branch backup-before-rewrite - Prefer git-filter-repo (faster, safer) and review the result - Force-push a rewritten branch only with --force-with-lease
Highgit-alias-semantic-unverifiedThe invoked Git alias depends on shell expansion, contains a cycle, or exceeds dcg's bounded semantic analysis.
Explanation
Review the fully expanded Git executable, alias chain, shell-alias body, and appended arguments before allowing execution. Dynamic shell values, cycles, and commands beyond the semantic parser's bounds can hide destructive operations.
Highlfs-migrate-rewritegit lfs migrate import/export rewrites history — every commit in the range gets a new SHA.
Explanation
git lfs migrate import/export rewrites the commits it touches: - Every rewritten commit gets a NEW SHA, so the branch diverges from every clone and a force-push is required to publish it - Collaborators' branches, open PRs and CI pins all break - `--everything` rewrites every local ref, not just the current branch - The original objects survive only until the next `git gc` prunes the unreachable ones Preview without rewriting anything: - git lfs migrate info: report what WOULD be converted - git lfs migrate info --everything --above=1MB Back the refs up first: git branch backup/pre-lfs-migrate
Highreflog-expire-nowgit reflog expire --expire=now destroys the reflog, removing the ability to recover lost commits.
Explanation
The reflog records where HEAD and each branch pointed, and is what lets you recover from a bad reset, rebase, or branch deletion. Expiring it with --expire=now deletes those entries immediately; after a subsequent gc --prune=now the orphaned commits cannot be recovered at all. Safer alternatives: - Let the reflog expire on its default schedule (90 days) - Recover what you need first: git reflog, then git branch <name> <sha>
Highreset-mergegit reset --merge can lose uncommitted changes.
Explanation
git reset --merge resets the index and updates files in the working tree that differ between the target commit and HEAD, but keeps changes that are not staged. However, if there are uncommitted changes in files that need to be updated, those changes will be lost. Safer alternatives: - git stash: Save uncommitted changes before reset - git merge --abort: If in the middle of a merge, abort safely Preview what would change: git status && git diff
Highrestore-worktreegit restore discards uncommitted changes. Use 'git stash' or 'git diff' first.
Explanation
git restore <path> discards uncommitted changes in your working directory, reverting files to their last committed state. Changes that were never committed are permanently lost. Safer alternatives: - git restore --staged <path>: Only unstage, keeps working directory changes - git stash: Save all changes temporarily - git diff <path>: Review what would be lost Preview changes first: git diff <path> Recovering from a failed `git pull --rebase`? Run `dcg rebase-recover` in this repo, then retry the command on its own line (a leading `cd <repo> &&` is fine; nothing else may share the line). This issues a short-lived, single-shot permit that unblocks this rule only. A rebase already in progress (`.git/rebase-merge/` or `.git/rebase-apply/` present) auto-allows the same rule without a permit.
Highrestore-worktree-explicitgit restore --worktree/-W discards uncommitted changes permanently.
Explanation
git restore --worktree (or -W) explicitly targets your working directory, discarding uncommitted changes. Even when combined with --staged, the worktree changes are permanently lost. Safer alternatives: - git restore --staged <path>: Only unstage, keeps working directory - git stash: Save changes first Preview changes first: git diff <path>
Highrm-forcegit rm -f deletes files even when they have uncommitted modifications. Commit or stash them first.
Explanation
git rm --force removes the named files from the index AND the working tree, bypassing the check that would otherwise refuse when they differ from HEAD. Committed content can be restored from history, but any uncommitted edits to those files are gone. Safer alternatives: - git rm --cached <path>: stop tracking but keep the file on disk - git rm -n <path>: preview which files would be removed - git stash or git commit first, then git rm without -f
Highshow-redirect-overwrite-sourcegit show <ref>:<path> redirected onto the same <path> overwrites the working tree file, exactly like the denied 'git checkout <ref> -- <path>'.
Explanation
Redirecting `git show <ref>:<path>` back onto `<path>` replaces the working-tree file with the version from another commit or branch. Any uncommitted changes to that file are permanently lost — the same hazard `checkout-ref-discard` exists to prevent, reached through a redirect instead of a checkout. The piped spelling `git show <ref>:<path> | tee <path>` reaches the same overwrite and is just as unsafe. Safer alternatives: - Redirect to a NEW file, then inspect: `git show <ref>:<path> > <path>.from-ref` - git stash: Save changes first, then take the other version, then 'git stash pop' - Bare `git show <ref>:<path>` (no redirect) only prints and is always allowed. Preview what would change: git diff HEAD <ref> -- <path>
Highswitch-discardgit switch --discard-changes/-f discards all uncommitted changes to tracked files. Use 'git stash' first.
Explanation
git switch --discard-changes (alias -f/--force) switches branches and throws away local modifications that would otherwise block the switch. They were never committed, so they cannot be recovered. Safer alternatives: - git stash: save the changes, switch, then 'git stash pop' - git switch -c <new-branch>: carry the changes to a new branch instead - git worktree add ../other <branch>: check the branch out alongside
Highupdate-ref-deletegit update-ref -d deletes a ref (e.g. a branch) outright, like git branch -D.
Explanation
git update-ref -d is the plumbing form of deleting a ref. Pointed at refs/heads/<branch> it is git branch -D without the safety messages; commits reachable only from that ref survive only in the reflog. Safer alternatives: - git branch -vv: review the ref first - git branch backup/<name> <ref>: keep a pointer before deleting - git branch -d <branch>: the porcelain delete, which refuses unmerged branches
Mediumlfs-prunegit lfs prune deletes local LFS objects; with --force it deletes objects the remote does not have.
Explanation
git lfs prune deletes local Git LFS objects from .git/lfs/objects: - Objects older than the fetch/push retention window are removed - Anything the remote also has is re-downloadable, so the usual case is recoverable — at the cost of a re-fetch - `--force` / `-f` prunes objects even when the remote is NOT known to have them, which can destroy the only copy of unpushed content - `--recent` widens what is kept; it does not make the delete safer Check what would go first: - git lfs prune --dry-run --verbose - git lfs prune --verify-remote: only prune what the remote confirms
Mediumlfs-uninstallgit lfs uninstall removes the LFS filters and hooks, so LFS files check out as pointer text.
Explanation
git lfs uninstall removes Git LFS from the git configuration: - The clean/smudge filters go, so tracked binaries check out as one-line pointer files — and a later `git add`/commit can write those pointers back over real content - The pre-push hook goes, so LFS objects stop being uploaded and a push can publish pointers with no objects behind them - `--system` and `--global` affect EVERY repository on the machine, not just this one Check the current configuration first: git lfs env Re-enable with: git lfs install
Mediumstash-dropgit stash drop deletes a single stash. Recoverable via `git fsck` (unreachable objects).
Explanation
git stash drop removes a specific stash entry from your stash list. The stashed changes become unreferenced but remain in git's object database temporarily. They can often be recovered using git fsck, but this is not guaranteed and becomes harder over time as git garbage collects. Safer alternatives: - git stash pop: Apply and drop in one step (only drops if apply succeeds) - git stash apply: Apply without dropping, verify first Recovery if needed: git fsck --unreachable | grep commit git show <commit-hash> # Inspect each to find your stash
Safe patterns
Checked first. A command that matches one is never blocked by this pack.
checkout-new-branchcheckout-orphanrestore-staged-longrestore-staged-shortclean-dry-run-shortclean-dry-run-longlfs-prune-dry-run