--- name: git-sync path: .git disable-model-invocation: true description: "Use for Git pull/sync: fetch, rebase, test; push only when publication requested. For dirty trees or merge/rebase planning use merge-plan." --- # Git Sync Preserve unrelated work, keep history linear, never force-push, and never bypass hooks autonomously. ## Resolve context - Require a clean tree, an attached branch, and no merge, rebase, cherry-pick, or revert in progress. - Resolve the remote from the current branch's configured upstream. With no upstream, use the sole configured remote; if several exist, ask. - Resolve an explicit target first. Otherwise use the remote's symbolic HEAD, then the first existing remote branch among `trunk`, `main`, `master`, and `develop`. Do not mutate remote configuration merely to discover the target. ## Procedure 1. Record the current branch, remote, target, and current commit. 2. Fetch the resolved remote with pruning and tags. 3. Count the current commits above the remote target; warn before rebasing more than 50. 4. Rebase the current branch onto the fetched target. 5. On conflicts, stop and report the conflicted files, status, and exact continuation or abort choices. 6. Compare the resulting stack with the recorded stack and report unexpectedly dropped commits. 7. Run repository-required gates plus requested or obvious fast checks. Stop when a required check fails. 8. Push only when the user or encompassing request authorized publication. Otherwise stop after local synchronization. 9. Push the current branch normally. If rejected, fetch, rebase, and test once more, then retry once. If a hook fails, preserve its edits and stop with the failing command and evidence. 10. Report branch, target, remote, whether a rebase occurred, checks, publication authorization, and any pushed commit. ## Interrupted rebases and autostash With `rebase.autostash` or `merge.autostash` enabled, Git stashes a dirty tree before rebasing and restores it afterwards. When the operation is interrupted between those steps — failing hook, failing content filter, aborted or timed-out command — the restore never happens. The result is silent: an unexpected stash entry named `autostash` holds the work while the affected files look modified or deleted in the worktree. - After any interrupted or failed fetch, rebase, merge, or pull, run `git stash list` before touching the worktree. - Treat an `autostash` entry you did not create as unrestored work: inspect it with `git stash show -p`, restore it with `git stash apply`, and only drop it once its content is confirmed present. - Never resolve files that Git reports as deleted after such a failure by committing the deletion; recover the stash first. - Prefer committing the work before synchronizing, so autostash never triggers.