Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Commit Pr?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/rashadansari-commit-pr)
---
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.