Examples in use

Checking out a pull request locally

Using pull request number

You can check out any pull request, including from forks, in a repository using its pull request number

// Checking out a pull request locally
~/Projects/my-project$ gh pr checkout 12
remote: Enumerating objects: 66, done.
remote: Counting objects: 100% (66/66), done.
remote: Total 83 (delta 66), reused 66 (delta 66), pack-reused 17
Unpacking objects: 100% (83/83), done.
From https://github.com/owner/repo
 * [new ref]             refs/pull/8896/head -> patch-2
M       README.md
Switched to branch 'patch-2'

~/Projects/my-project$

Using other selectors

You can also use URLs and branch names to checkout pull requests.

// Checking out a pull request locally
~/Projects/my-project$ gh pr checkout branch-name
Switched to branch 'branch-name'
Your branch is up to date with 'origin/branch-name'.
Already up to date.

~/Projects/my-project$

Creating issues and pull requests

Interactively

# Create a pull request interactively
~/Projects/my-project$ gh pr create
Creating pull request for feature-branch into master in owner/repo
? Title My new pull request
? Body [(e) to launch nano, enter to skip]
http://github.com/owner/repo/pull/1
~/Projects/my-project$
# Create an issue interactively
~/Projects/my-project$ gh issue create
Creating pull request for feature-branch into master in owner/repo
? Title My new issue
? Body [(e) to launch nano, enter to skip]
http://github.com/owner/repo/issues/1
~/Projects/my-project$

With flags

# Create a pull request using flags
~/Projects/my-project$ gh pr create --title "Pull request title" --body "Pull request body"
http://github.com/owner/repo/pull/1
~/Projects/my-project$
# Create an issue using flags
~/Projects/my-project$ gh issue create --title "Issue title" --body "Issue body"
http://github.com/owner/repo/issues/1
~/Projects/my-project$

In the browser

// Quickly navigate to the pull request creation page
~/Projects/my-project$ gh pr create --web
Opening https://github.com/owner/repo/pull/branch in your browser.
~/Projects/my-project$
// Quickly navigate to the issue creation page
~/Projects/my-project$ gh issue create --web
Opening https://github.com/owner/repo/issues/new in your browser.
~/Projects/my-project$

Working with forks

This command will automatically create a fork for you if you're in a repository that you don't have permission to push to.

Using lists of issues or pull requests in a repository

Default behavior

You will see the most recent 30 open items.

# Viewing a list of open pull requests
~/Projects/my-project$ gh pr list

Pull requests for owner/repo

#14  Upgrade to Prettier 1.19                           prettier
#14  Extend arrow navigation in lists for MacOS         arrow-nav
#13  Add Support for Windows Automatic Dark Mode        dark-mode
#8   Create and use keyboard shortcut react component   shortcut

~/Projects/my-project$
# Viewing a list of open issues
~/Projects/my-project$ gh issue list

Issues for owner/repo

#14  Update the remote url if it changed  (bug)
#14  PR commands on a detached head       (enhancement)
#13  Support for GitHub Enterprise        (wontfix)
#8   Add an easier upgrade command        (bug)

~/Projects/my-project$

Filtering with flags

You can use flags to filter the list for your specific use cases.

# Viewing a list of closed pull requests assigned to a user
~/Projects/my-project$ gh pr list --state closed --assignee user

Pull requests for owner/repo

#13  Upgrade to Electron 7         electron-7
#8   Release Notes Writing Guide   release-notes

~/Projects/my-project$
# Viewing a list of closed issues assigned to a user
~/Projects/my-project$ gh issue list --state closed --assignee user

Issues for owner/repo

#13  Enable discarding submodule changes  (bug)
#8   Upgrade to latest react              (upgrade)

~/Projects/my-project$

Viewing the status of your relevant work

Pull requests

# Viewing the status of your relevant pull requests
~/Projects/my-project$ gh pr status
Current branch
  #12 Remove the test feature [user:patch-2]
   - All checks failing - Review required

Created by you
  You have no open pull requests

Requesting a code review from you
  #13 Fix tests [branch]
  - 3/4 checks failing - Review required
  #15 New feature [branch]
   - Checks passing - Approved

~/Projects/my-project$

Issues

# Viewing issues relevant to you
~/Projects/my-project$ gh issue status
Issues assigned to you
  #8509 [Fork] Improve how Desktop handles forks  (epic:fork, meta)

Issues mentioning you
  #8938 [Fork] Add create fork flow entry point at commit warning  (epic:fork)
  #8509 [Fork] Improve how Desktop handles forks  (epic:fork, meta)

Issues opened by you
  #8936 [Fork] Hide PR number badges on branches that have an upstream PR  (epic:fork)
  #6386 Improve no editor detected state on conflicts modal  (enhancement)

~/Projects/my-project$

Viewing a pull request or issue

In the browser

Quickly open a pull request or issue in the browser.

# Viewing a pull request in the browser
~/Projects/my-project$ gh pr view 21
Opening https://github.com/owner/repo/pull/21 in your browser.
~/Projects/my-project$
# Viewing an issue in the browser
~/Projects/my-project$ gh issue view 21
Opening https://github.com/owner/repo/issues/21 in your browser.
~/Projects/my-project$

In terminal

Use --preview or -p to view a preview of the title and body.

# Viewing a pull request in terminal
~/Projects/my-project$ gh pr view 21 --preview
Hide PR number badges on branches that have an upstream PR
opened by user. 0 comments. (enhancement)

  While we're in a state where we're not displaying upstream pull requests in the PR list, we should
  hide the `#XX` badge to avoid confusion.

View this pull request on GitHub: https://github.com/owner/repo/pull/21
~/Projects/my-project$
# Viewing an issue in terminal
~/Projects/my-project$ gh issue view 21 --preview
Onboarding blankstate responsive bugs
opened by user. 0 comments. (bug)

  Noticed some tiny visual bugs with the responsive blankstates

  - Some text bumping into each other at certain sizes
  - Line height on h1
  - When you expand the commit area panel everything breaks

View this issue on GitHub: https://github.com/owner/repo/issues/21
~/Projects/my-project$