Merge a PR and clean up its feature branch.
$ARGUMENTS optionally specifies a GitHub PR number (e.g., "166"). If
omitted, infer the PR from the current branch using gh pr view.
Steps:
Find the PR.
- If $ARGUMENTS contains a PR number: use
gh pr view <number>to get the PR's branch name, URL, and state. - If $ARGUMENTS is empty: use
gh pr view(infers from current branch). - If the PR is not open, report the issue and stop.
- If $ARGUMENTS contains a PR number: use
Check out the PR's branch if not already on it:
git checkout <branch-name>.Merge the PR with
gh pr merge <url> --squash --delete-branch. This squashes the PR's commits into a single commit on main and deletes both the local and remote feature branches.Switch to main:
git checkout main.Pull remote main:
git pull origin main.Verify branch cleanup.
--delete-branchshould have removed both local and remote. If either remains (e.g. gh couldn't delete the local branch because it wasn't fast-forward), finish the job:git branch -D <branch-name>(squash merges require-D, not-d, because the squashed commit is not a descendant of the feature branch).git push origin --delete <branch-name>
Confirm cleanup with
git branchandgit status.