--- name: github-prs description: Find, inspect, and create GitHub pull requests for a branch using the GitHub CLI and git. Use when you need to locate the PR tied to a branch or open/update a PR. --- # GitHub PRs (branch workflows) This skill documents common GitHub CLI workflows for finding a PR for a branch, inspecting it, and creating one if needed. ## Prerequisites - Repository has a GitHub remote (usually `origin`). - GitHub CLI (`gh`) is installed and authenticated (`gh auth status`). ## Find the PR for the current branch ```bash # Show current branch branch=$(git rev-parse --abbrev-ref HEAD) # Find PR for the current branch (if one exists) gh pr list --head "$branch" --state all # View the PR details by branch pr_number=$(gh pr list --head "$branch" --state all --json number --jq '.[0].number') if [ -n "$pr_number" ]; then gh pr view "$pr_number" --web fi ``` ## Find PRs by branch name (explicit) ```bash branch="feature/your-branch" gh pr list --head "$branch" --state all ``` ## Find the PR for the current branch (alternative via git) ```bash # If upstream is set, this is handy for branch -> PR lookup upstream=$(git rev-parse --abbrev-ref --symbolic-full-name @{u}) if [ -n "$upstream" ]; then gh pr list --head "${upstream#origin/}" --state all fi ``` ## Create a PR from the current branch ```bash branch=$(git rev-parse --abbrev-ref HEAD) # Push branch if needed if ! git rev-parse --symbolic-full-name "${branch}@{u}" >/dev/null 2>&1; then git push -u origin "$branch" fi # Create PR (edit title/body as needed) gh pr create \ --title "[ISSUE-123] Short summary" \ --body $'[![developer_preview](https://img.shields.io/badge/Web_App_Preview-ready-green?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAADpSURBVHgBtZOBEYIwDEVTzwF0g7pJ3QQnkI3USRgBNygbwAYxKeUM2ObKCf8uV6Cvv01oAPYSIlqKhqLHUfxsE5wTHMfjh4tmHtNyC7OU/MyUXp6YVys4r3ANMyaCPQ0npSKXOHqFGYwx5wNsp3CgyfCtgB3tHIJPASVSis2qBFcrHKZMvZjnK1EnNq8w83N43iQW2DAxpqhlZZffeM0R/lR245hyKzLwsn6Cu+O3mybOLSGLedWCqxTOScNGAXvBeYWbdQqCrtWdUnZhdRV3yipNhjeKDjZQMIx36Urxgnz6A+il6WAPfQCiq+BEGLOCVwAAAABJRU5ErkJggg==)](https://awac.attio.com/redirect/developer-preview/)\n\n\n\n- Summary bullet 1\n- Summary bullet 2\n' ``` ## Update an existing PR body ```bash pr_number= # Edit in editor EDITOR=vim gh pr edit "$pr_number" --body-file - # Or overwrite directly gh pr edit "$pr_number" --body $'...' ``` ## Quick checks ```bash # Confirm gh auth and repo gh auth status gh repo view --web ``` ## Troubleshooting - If `gh pr list --head` returns nothing, the PR may not exist yet, or the branch name differs. - Use `git branch -r | rg ` to confirm the remote branch name. - Ensure you're in the correct repo (`git remote -v`).