gh-upstream-release

Squash ahead commits, force-push to upstream, and merge a GitHub PR via gh CLI.

3|1|Updated Apr 14, 2026
One-click install
npx skills add https://github.com/ZHLX2005/sl --skill gh-upstream-release-zhlx2005
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gh-upstream-release
Source: https://github.com/ZHLX2005/sl/tree/main/skills/gh-upstream-release
Command: npx skills add https://github.com/ZHLX2005/sl --skill gh-upstream-release-zhlx2005

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When working in a fork-based GitHub workflow, feature branches often accumulate many small commits ahead of upstream/master. This Skill automates the end-to-end release SOP: squashing those commits into one, force-pushing to the upstream remote, opening a PR with the gh CLI, and squash-merging it into the main branch. ## Core Features & Use Cases - Commit Squashing: Detects how many commits the current branch is ahead of upstream/master and collapses them into a single commit via soft reset. - Safe Force Push: Pushes with --force-with-lease instead of --force to avoid overwriting others' work, with a diagnostic table for common push failures. - Automated PR Lifecycle: Auto-detects the base branch (main/master), creates the PR with gh pr create, squash-merges with --delete-branch, and reports full PR details including changed files and merge commit. - Use Case: You have 5 WIP commits on a feature branch in your fork and want to ship them as one clean commit to the canonical repository. This Skill handles the entire squash, push, PR, and merge sequence with built-in error recovery. ## Quick Start Ask the AI to squash my current branch's commits ahead of upstream, push to upstream, and open and squash-merge a PR using gh.

Frequently Asked Questions about gh-upstream-release

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I squash multiple commits and push to an upstream GitHub repository?

Count ahead commits with git rev-list --count upstream/master..HEAD, run git reset --soft upstream/master, commit once, then push with git push upstream HEAD --force-with-lease. The soft reset preserves all changes staged for the new single commit.

How to create and merge a GitHub PR from the command line with gh?

Use gh pr create with --repo, --base, --head, --title, and --body flags, then merge with gh pr merge <num> --squash --delete-branch. The base branch can be auto-detected from the upstream remote HEAD.

Why should I use --force-with-lease instead of git push --force?

--force-with-lease refuses the push if the remote branch was updated by someone else since your last fetch, preventing accidental overwrites. Plain --force overwrites the remote unconditionally and can destroy collaborators' work.

What causes gh pr create to fail with HTTP 422 Validation Failed?

HTTP 422 usually means a PR already exists for the same head-to-base branch pair, or the specified base branch does not exist. Check existing PRs with gh pr list --head <branch> and verify the base branch name.

When should I not squash commits before opening a PR?

Skip squashing when the branch has zero commits ahead of upstream, since a soft reset with n=0 can accidentally bundle unrelated working-tree changes. A single commit also does not require squashing unless explicitly requested.