{"slug": "opencode-commands-safe-git-commit-and-clear-safe-git-safe-git-commits-with", "title": "OpenCode commands: /safe-git-commit and /clear-safe-git — safe git commits with automatic backup snapshots", "summary": "OpenCode introduced two new commands, /safe-git-commit and /clear-safe-git, that enable developers to safely commit changes with automatic backup snapshots. The /safe-git-commit command creates a backup ref before staging and committing, allowing recovery if anything goes wrong. The /clear-safe-git command cleans up backup refs when no longer needed.", "body_md": "| description |\nSafely commit changes with automatic backup snapshot |\n| agent |\nbuild |\n\n!`BRANCH=$(git rev-parse --abbrev-ref HEAD) && BASE=$(git rev-parse HEAD) && REF_NAME=\"$BRANCH-$(date +%s)-$$\" && ORIG_INDEX=$(git write-tree) && git add -A && STASH=$(git stash create -u) && git read-tree $ORIG_INDEX && if [ -n \"$STASH\" ]; then git update-ref \"refs/safe-git/$REF_NAME\" $STASH && printf 'BACKUP CREATED\\nBase: %s\\nStash: %s\\nRef: refs/safe-git/%s\\nRecovery: \"git reset --hard %s && git stash apply --index refs/safe-git/%s && git update-ref -d refs/safe-git/%s\"\\nCleanup: \"git update-ref -d refs/safe-git/%s\"\\n' \"$BASE\" \"$STASH\" \"$REF_NAME\" \"$BASE\" \"$REF_NAME\" \"$REF_NAME\" \"$REF_NAME\"; else echo 'NO CHANGES — working tree is clean. Nothing to snapshot.'; fi`\n\nIf the output above says NO CHANGES, tell the user \"Nothing to snapshot — working tree is clean\" and stop. Do nothing else.\n\nIf the output says BACKUP CREATED, follow this procedure:\n\n-\n**Echo the recovery and cleanup commands to the user BEFORE making any changes.** Copy the exact Recovery and Cleanup lines from the output above and show them to the user. This ensures they can recover or clean up manually if needed.\n\n-\nProcess the current changes and split them into logical, well-described commits. Stage hunks, make individual commits with meaningful messages.\n\n-\n**If anything goes wrong** — a bad commit, incorrect staging, validation failure, or any error — run the recovery commands shown above to automatically restore the working directory and staging area (to the state before any changes were made). Then stop and report what happened.\n\n-\n**Do NOT clean up the backup ref automatically** after committing. Leave the backup ref in place. Only delete it if the user explicitly asks with a command like \"clean up the backup\" or by running the Cleanup command themselves.", "url": "https://wpnews.pro/news/opencode-commands-safe-git-commit-and-clear-safe-git-safe-git-commits-with", "canonical_source": "https://gist.github.com/bendtherules/4e21b9aaf17b6ae0f959ece72f2ad12c", "published_at": "2026-06-15 13:41:23+00:00", "updated_at": "2026-06-15 14:07:01.298302+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["OpenCode"], "alternates": {"html": "https://wpnews.pro/news/opencode-commands-safe-git-commit-and-clear-safe-git-safe-git-commits-with", "markdown": "https://wpnews.pro/news/opencode-commands-safe-git-commit-and-clear-safe-git-safe-git-commits-with.md", "text": "https://wpnews.pro/news/opencode-commands-safe-git-commit-and-clear-safe-git-safe-git-commits-with.txt", "jsonld": "https://wpnews.pro/news/opencode-commands-safe-git-commit-and-clear-safe-git-safe-git-commits-with.jsonld"}}