GitHub CLI Cheatsheet
Pull Requests
Use this GitHub CLI reference while you build software engineering projects, review code, or refresh the syntax you reach for most.
Creating a PR
From a branch with commits pushed, gh pr create prompts for title and body. --fill skips the prompts by reusing the commits.
gh pr create --fill # title+body from the commits gh pr create --fill-first # title+body from the first commit only gh pr create --fill-verbose # every commit message and body gh pr create -t "fix: null guard" -b "closes #42" gh pr create --base main --head feature/login gh pr create --draft --fill gh pr create --body-file ./pr.md gh pr create --body-file - < CHANGELOG.md gh pr create --template .github/PULL_REQUEST_TEMPLATE.md gh pr create --reviewer alice,bob --reviewer my-org/platform gh pr create --assignee @me --label bug --label needs-docs gh pr create --milestone "v2.1" --project Roadmap gh pr create --web # open the compare page instead gh pr create --dry-run --fill # print what would be created
| Flag | Effect |
|---|---|
-f, --fill | Title and body from the branch's commits, no prompts |
-B, --base | Target branch, defaults to the repo's default branch |
-H, --head | Source branch, defaults to the current one |
-d, --draft | Open as a draft |
-t, --title, -b, --body | Set them inline |
-F, --body-file | Read the body from a file, - for stdin |
-T, --template | Start from a PR template file |
-r, --reviewer | Users or org/team handles, repeatable or comma separated |
-a, --assignee | Logins, @me for yourself |
-l, --label, -m, --milestone, -p, --project | Metadata by name or title |
-e, --editor | Write title and body in $EDITOR, first line is the title |
-w, --web | Open the browser compare view |
--dry-run | Print the PR details without creating it |
--no-maintainer-edit | Block upstream maintainers from pushing to your branch |
--recover <file> | Recover the input from a failed create run |
If the branch is not pushed yet, gh offers to push it and to create a fork when you lack write access. --dry-run may still perform that push.
Listing and Searching
gh pr list # open PRs, 30 by default gh pr list --state all --limit 100 gh pr list --state merged --author "@me" gh pr list --author alice --label bug gh pr list --base main --head feature/login gh pr list --draft gh pr list --app dependabot gh pr list --search "review-requested:@me draft:false" gh pr list --search "is:open sort:updated-desc label:bug" gh pr list --search "created:>2026-01-01 -label:wip" gh pr list --json number,title,author,headRefName gh pr list --web
| Flag | Filter |
|---|---|
-s, --state | open (default), closed, merged, all |
-A, --author | Login or @me |
--app | Filter by GitHub App author, e.g. dependabot |
-a, --assignee | Login |
-l, --label | Repeatable |
-B, --base, -H, --head | Branch names. --head takes no owner:branch form |
-d, --draft | Drafts only |
-S, --search | Full GitHub search syntax, which beats the narrow flags |
-L, --limit | Max results |
--search accepts the same qualifiers as the web search box, so review-requested:@me, sort:updated-desc, -label:wip, and created:>DATE all work. Reach for it whenever the dedicated flags run out.
Your Own Queue
gh pr status # current branch, yours, and review requests gh pr status --conflict-status # add each PR's merge conflict state gh pr status --json number,title,statusCheckRollup
Three sections: the PR for the branch you are on, PRs you opened, and PRs waiting on your review. This is the one command to run at the start of the day.
Viewing
Every gh pr subcommand takes a number, a URL, a branch name, or nothing (meaning the current branch).
gh pr view # the current branch's PR gh pr view 123 gh pr view feature/login gh pr view https://github.com/cli/cli/pull/9999 gh pr view 123 --comments # include the comment thread gh pr view 123 --web gh pr view 123 --json title,body,files,reviews gh pr view 123 --json mergeable --jq .mergeable
Diffs
gh pr diff # the current branch's PR gh pr diff 123 gh pr diff 123 --name-only # just the changed paths gh pr diff 123 --patch # git format-patch output gh pr diff 123 --color always | less -R gh pr diff 123 --exclude "*.lock" --exclude "dist/*" gh pr diff 123 --web
--exclude takes globs, which is how you drop lockfiles and generated bundles from a review diff. --patch output can be piped straight into git apply.
Checking Out
gh pr checkout 123 gh pr checkout 123 --branch review-123 # local branch name gh pr checkout 123 --detach # detached HEAD, no branch created gh pr checkout 123 --force # reset an existing local branch gh pr checkout 123 --recurse-submodules gh pr checkout https://github.com/cli/cli/pull/9999
A PR from a fork works the same. gh configures the branch to fetch from the contributor's fork, so git pull picks up their new commits and, when the PR allows maintainer edits, git push pushes back to their branch. That is the whole reason to prefer gh pr checkout over hand-rolled git fetch refspecs.
Editing and State
gh pr ready # draft becomes ready for review gh pr ready 123 --undo # back to draft gh pr edit 123 --title "fix: guard null user" gh pr edit 123 --base develop gh pr edit 123 --body-file ./body.md gh pr edit 123 --add-label needs-review --remove-label wip gh pr edit 123 --add-reviewer alice --remove-reviewer bob gh pr edit 123 --add-assignee @me gh pr edit 123 --milestone "v2.1" gh pr edit 123 --remove-milestone gh pr close 123 --comment "superseded by #124" gh pr close 123 --delete-branch gh pr reopen 123 gh pr comment 123 --body "rebased on main" gh pr comment 123 --body-file notes.md gh pr comment 123 --edit-last --body "rebased and rerun" gh pr comment 123 --editor gh pr lock 123 --reason spam gh pr unlock 123
--edit-last updates your own most recent comment instead of adding another, and pairs with --create-if-none in a script that posts a single rolling status comment. --delete-last --yes removes it without a confirmation prompt.