PR Land
Overview
Land a ready GitHub PR with guardrails: resolve the current PR, wait for checks when the repository reports them, block on draft/requested-changes states, merge, clean up the branch, then return to the base branch and fast-forward pull.
Use the agent's normal "publish PR" workflow first when the user still needs local changes committed, pushed, or a PR opened. Use this skill after a PR exists.
Workflow
Resolve context.
- Run
git status -sb,git branch --show-current, andgh pr view --json number,title,url,headRefName,headRefOid,baseRefName,isDraft,reviewDecision,mergeStateStatus. - Before any commit or landing action, inspect staged paths and unstage anything that matches
.gitignorerules, including files nested inside ignored directories. Prefergit check-ignore --no-indexso force-added ignored files are caught. - If no PR is found for the current branch, ask for a PR number or URL.
- If the worktree still has uncommitted changes after unstaging ignored paths, stop before merge cleanup unless the user explicitly says they are unrelated and should be left alone.
- Run
Gate before merge.
- Stop if the PR is a draft.
- Stop if
reviewDecisionisCHANGES_REQUESTED. - Stop if
reviewDecisionisREVIEW_REQUIREDunless the user explicitly wants to try merging anyway. - If the local checked-out branch is the PR branch, ensure local
HEADequalsheadRefOid; otherwise ask whether to push/reconcile first.
Wait for CI when present.
- Prefer the bundled script from this skill directory.
- Windows PowerShell:
& .\scripts\land-pr.ps1 -Yes - macOS / Linux:
./scripts/land-pr.sh --yes - Use
-Pr 123or-Pr https://github.com/OWNER/REPO/pull/123when landing a PR that is not the current branch. - In Bash, use
--pr 123or--pr https://github.com/OWNER/REPO/pull/123. - Use
-MergeMethod merge,-MergeMethod squash, or-MergeMethod rebasewhen the user specifies a merge strategy. Default tosquash. - In Bash, use
--merge-method merge,--merge-method squash, or--merge-method rebase. - Use
-RequiredOnlywhen the user only wants required checks to gate the merge. - In Bash, use
--required-only. - A repository or PR with no reported checks is not a failure by itself. Continue after reporting that no CI checks were found.
Merge and clean up.
- The script first unstages ignored files, then merges with
gh pr merge --<method> --delete-branch, checks out the PR base branch, pulls withgit pull --ff-only origin <base>, and deletes the matching local PR branch only when it matches the PR head SHA. - If the script cannot safely delete the local branch, report the reason and leave it in place.
- The script first unstages ignored files, then merges with
Finish with the concrete result.
- Include PR number/title, merge method, final branch, whether checks passed or were absent, whether remote/local branch cleanup happened, and whether
git pull --ff-onlysucceeded.
- Include PR number/title, merge method, final branch, whether checks passed or were absent, whether remote/local branch cleanup happened, and whether
Manual Fallback
Use this sequence when the script is unavailable or needs adaptation:
gh pr checks --watch --fail-fast --interval 30 # If this reports no checks configured, continue instead of failing.
gh pr view --json number,title,url,headRefName,headRefOid,baseRefName,isDraft,reviewDecision,mergeStateStatus
gh pr merge <number> --squash --delete-branch
git checkout <baseRefName>
git pull --ff-only origin <baseRefName>
git branch -D <headRefName>
Before git branch -D, verify the local branch exists and its SHA equals the PR headRefOid.