Skip to content

Instantly share code, notes, and snippets.

@mishuagopian
Created January 6, 2026 16:29
Show Gist options
  • Select an option

  • Save mishuagopian/60a44bf23b5a4d16ef05fdd4da78c542 to your computer and use it in GitHub Desktop.

Select an option

Save mishuagopian/60a44bf23b5a4d16ef05fdd4da78c542 to your computer and use it in GitHub Desktop.
Cursor /commit-push-pr command

Commit, Push, and Create Pull Request

This command commits current work, pushes to the appropriate branch, and creates a pull request when needed.

Rules

  • NEVER push directly to main, master or develop branches
  • If currently on main, master or develop, create a new branch first
  • Generate meaningful commit messages based on the actual changes
  • Generate meaningful branch names in kebab-case (e.g., feat/add-user-authentication, fix/null-pointer-in-parser)
  • Skip PR creation if a PR already exists for the current branch
  • Use the repository's default branch as the PR base

Step 1: Check Current Branch

Run this command to determine the current branch:

git branch --show-current
  • If the branch is main, master or develop, proceed to Step 2 (create new branch)
  • If on any other branch, skip to Step 3 (stage and commit)

Step 2: Create New Branch (only if on main, master or develop)

First, analyze the changes to generate a meaningful branch name:

git status --short
git diff --stat

Based on the changes observed:

  • Determine the type: feat/, fix/, chore/, refactor/, docs/, test/
  • Create a descriptive kebab-case name summarizing the work
  • Example names: feat/add-discord-notifications, fix/handle-empty-response, chore/update-dependencies

Create and switch to the new branch:

git checkout -b <branch-name>

Step 3: Stage Changes

Check what files have been modified:

git status --short

Stage the relevant files. Exclude local configuration files like .vscode/, .cursor/, .idea/, etc.:

git add <files-to-stage>

Or to stage all relevant changes:

git add -A

Then unstage any local config files if they were accidentally added:

git reset HEAD .vscode/ .cursor/ .idea/ 2>/dev/null || true

Step 4: Generate Commit Message and Commit

Review the staged changes to create a meaningful commit message:

git diff --cached --stat
git diff --cached

Create a conventional commit with:

  • Format: type: short description
  • Types: feat:, fix:, chore:, refactor:, docs:, test:, perf:
  • Body: Include detailed bullet points of key changes if needed

Commit the changes:

git commit -m "type: short description" -m "- Detail 1
- Detail 2
- Detail 3"

Or for simple commits:

git commit -m "type: short description"

Step 5: Push to Remote

Push the branch to origin. Use -u flag if it's a new branch:

git push -u origin $(git branch --show-current)

Or if the branch already exists on remote:

git push origin $(git branch --show-current)

Step 6: Check for Existing Pull Request

Before creating a PR, check if one already exists for this branch:

gh pr list --head $(git branch --show-current) --state open
  • If a PR already exists, skip PR creation and proceed to the summary
  • If no PR exists, proceed to Step 7

Step 7: Create Pull Request

First, get the repository's default branch:

gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'

Create the pull request using the default branch as base:

gh pr create --base <default-branch> --title "<PR Title>" --body "<PR Body>"

PR Title: Should match or expand on the commit message summary

PR Body Format:

## Summary
Brief description of what this PR does.

## Changes
- **File/Component**: Description of change
- **File/Component**: Description of change

## Testing
How it was tested / which tests were added.

Step 8: Summary

After completing all steps, provide a summary with:

  1. Branch name: The branch that was pushed to
  2. Commit message: The commit message that was used
  3. PR URL: The URL of the created PR (or note if PR already existed/was skipped)
  4. Status: Success or any issues encountered

Example summary format:

βœ… Successfully committed and pushed!

πŸ“Œ Branch: feat/add-user-notifications
πŸ“ Commit: feat(notifications): add Discord webhook integration
πŸ”— PR: https://github.com/owner/repo/pull/123

Or if PR already existed:

βœ… Successfully committed and pushed!

πŸ“Œ Branch: feat/add-user-notifications
πŸ“ Commit: feat(notifications): add Discord webhook integration
ℹ️  PR already exists - skipped PR creation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment