The first PR exists before you open GitHub
The first PR is the URL gh prints. You never have to open Compare.
Pushed the branch and still opening GitHub to click Compare? Skip the tab. gh pr create prints the pull URL on success—that is the first PR. If you still need a shared canvas, start a room.
Stop when the command prints a URL, you have a GitHub remote, and you can push or fork. Search query: install gh, auth login, first PR from the terminal
Put gh on PATH first
- 1macOS
Homebrew:
brew install gh. Thengh --version. - 2Windows
winget install --id GitHub.cli. Open a new terminal and check the version. - 3Linux
Add the official apt/dnf repo from cli.github.com, then install
gh. Do not rely on a stale distro package alone. - 4Confirm the binary
which ghandgh --versionmust resolve. Fix PATH if they do not.
gh auth login only proves who you are
Default is a web OAuth flow. Hostname defaults to github.com. Use --hostname for GitHub Enterprise. Headless: --with-token reads a classic PAT from stdin (manual minimum scopes: repo, read:org, gist).
gh auth login
gh auth status
# headless classic PAT:
# gh auth login --with-token < mytoken.txtCreate the first PR in the terminal
Branch, commit, get the head onto a remote. If the branch is not fully pushed, gh pr create asks where to push. --title and --body skip the editor. Success is a line like https://github.com/…/pull/N.
git checkout -b fix-docs
git add .
git commit -m "Fix docs"
git push -u origin fix-docs
gh pr create --title "Fix docs" --body "What changed and why."
# printed: https://github.com/owner/repo/pull/1
gh pr viewPermissions stall you, not the tab
No push access means a fork
The manual: if the current branch is not fully pushed, gh prompts. If you cannot push upstream, it can create a fork with only the default branch. --head skips automatic fork/push.
Keep tokens out of git
Read a PAT from a file or the environment. Do not commit it. Sign out with gh auth logout.
Compare is a web shortcut. The /pull/N URL gh prints is the PR.
If the PR write-up has to match a diagram, put both on one page: guide · hereink room
Do I have to open github.com?
Not to create the PR. gh pr create prints the URL on success. --web opens the create page. Default auth login may open a browser for OAuth; that is login, not PR create.
Does this fight an existing git clone?
No. A GitHub remote is enough. You do not need gh repo clone.
Why does it say there is no repository?
Run it inside a git repo whose origin is GitHub, or pass -R owner/repo.
How do I open a draft?
Add --draft. Set the target with --base. Inspect with gh pr view, not --web by default.