Skip to content
Back to skills

Commit Pr

ASecurity

Squash the branch into one commit and open or update its pull request (creates a new branch first if on main/master)

  • 6 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 10, 2026
ai-agentsshellbashgit

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 10, 2026

npx -y skills add RashadAnsari/myagents --skill commit-pr --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Commit Pr?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Commit Pr
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/rashadansari-commit-pr/badge)](https://www.skillsdirectory.com/skills/rashadansari-commit-pr)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: commit-pr
disable-model-invocation: true
description: Squash the branch into one commit and open or update its pull request (creates a new branch first if on main/master)
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git diff:*), Bash(git branch:*), Bash(git checkout:*), Bash(git log:*), Bash(git fetch:*), Bash(git merge-base:*), Bash(git reset --soft:*), Bash(git commit:*), Bash(git push:*), Bash(gh pr create:*), Bash(gh pr view:*), Bash(gh pr edit:*), Bash(gh repo view:*)
---

## Context

The `!` prefix on each line below runs the shell command inline and injects its output before the prompt is submitted. If the lines below still show the literal commands, this platform does not expand them: run each command yourself first and use its output as the context.

- Current git status: !`git status`
- Current git diff (staged and unstaged changes): !`git diff HEAD`
- Current branch: !`git branch --show-current`
- Recent commits: !`git log --oneline -10`
- Default branch: !`gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name' 2>/dev/null || echo "main"`

## Your task

Based on the above changes, create or update the pull request so that it holds exactly one commit (the single-commit pull request rule). Follow these steps in order:

### Step 1: Branch check

Read the current branch from the context above.

If the current branch is `main` or `master`:
1. Generate a short, kebab-case branch name that describes the staged changes (e.g. `fix-login-validation`, `add-user-settings`). Keep it under 40 characters.
2. Run: `git checkout -b <branch-name>`

Otherwise, stay on the current branch. Do not switch branches.

### Step 2: Squash into one commit

Infer the commit message format from the recent commits shown above: match the exact style, prefix convention, casing, and structure used in this project. Do not impose an external convention if the project already has one.

Only rewrite a branch you or the user created for this pull request. If someone else has pushed to it (their commits appear in `git log origin/<current-branch>`), stop and ask the user.

Stage all changed files, then fold the whole branch into one commit:

```bash
git fetch origin <default-branch>
git reset --soft "$(git merge-base HEAD origin/<default-branch>)"
git commit -m "<message>"
```

The message describes the whole branch, not only the latest changes.

### Step 3: Push

If Step 1 created the branch, or the branch has never been pushed:
```
git push -u origin <current-branch>
```

Otherwise the squash rewrote pushed history, so push with a lease:
```
git push --force-with-lease -u origin <current-branch>
```

### Step 4: Build PR title and body from branch diff

Run both in parallel:

```bash
git log <default-branch>..<branch> --oneline
```

```bash
git diff <default-branch>..<branch>
```

Using all commits and the full diff between the branch and the default branch:
- Derive a concise PR title that summarises the overall change (not just the latest commit).
- Derive a 2-4 sentence PR body that describes what the branch does as a whole.

### Step 5: Create or update the PR

Check whether a PR already exists for this branch:

```bash
gh pr view --json number,url 2>/dev/null
```

If a PR exists, update it:
```bash
gh pr edit --title "<title>" --body "<body>"
```

If no PR exists, create one:
```bash
gh pr create \
  --title "<title>" \
  --base <default-branch> \
  --head <branch> \
  --body "<body>"
```

### Rules

- Do not use any other tools or do anything else beyond these five steps.
- Never use a plain `git push --force`; always use `--force-with-lease`.
- Do not send any text besides the tool calls and, at the very end, a single short confirmation line with the PR URL.
- If `gh` is not available or not authenticated, print the URL shown in the `git push` output and tell the user to open the PR manually.

Files in this skill

  • SKILL.md3.8 KB
  • agents/openai.yaml209 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.