squash-and-push
Squash the current branch's full history since its base into one commit and force-push with lease. Manual command — run with /squash-and-push when the user asks to squash and push the current branch a
Files1
View on GitHubSKILL.mdskills/squash-and-push/SKILL.md
GitHubSquash and Push
Squash all commits on the current branch (since it diverged from the base branch) into one commit, then push with --force-with-lease.
Safety + scope checks
- Run
git branch --show-current; abort if onmain/master. - Run
git status --shortandgit rev-parse --abbrev-ref --symbolic-full-name @{u}. - If upstream is missing, stop and ask which base/upstream to use.
- Run
git fetch origin main(substitute the repo's actual default branch throughout).
- Run
Commit working changes first (required when dirty)
- If
git status --shortis not empty, stage withgit add -Aand commit using the repo's commit-message convention. - Always pass the commit message via HEREDOC.
- If
Determine the full squash span
- Use the base branch as the root reference:
BASE=$(git merge-base origin/main HEAD)BRANCH_COMMITS=$(git rev-list --count "$BASE..HEAD")
- Sanity check to avoid misparsed ranges:
MAIN_DELTA=$(git rev-list --count origin/main..HEAD)- If
BRANCH_COMMITSandMAIN_DELTAdiffer, stop and report the blocker before squashing.
- The span is always the full branch history since base — including commits already pushed — never just
@{u}..HEAD. - If
BRANCH_COMMITSis0, report the blocker (nothing to squash) and stop.
- Use the base branch as the root reference:
Squash into one commit
git add -A.- If
BRANCH_COMMITS > 1, rungit reset --soft HEAD~$BRANCH_COMMITS. - Create one final commit in the repo's message convention, via HEREDOC.
Push safely
git push --force-with-lease.
Verify + report
git status --short(expect clean).- Recompute:
git rev-list --count "$(git merge-base origin/main HEAD)..HEAD"(expect1) andgit rev-list --count origin/main..HEAD(expect1). - Report branch name, new commit SHA, and confirmation of a single-commit branch.
Hard constraints
- Never calculate the squash span from
@{u}..HEAD. - Never run
git reset --soft origin/mainor any non-HEAD~Nreset target for the squash. - Never use plain
--force; always--force-with-lease. - If conflicts or errors occur, stop and report the exact blocker before retrying.