How to install and use GitHub CLI (gh): auth, clone, and open a PR

Install GitHub CLI, finish gh auth login, and clone a repository or create a pull request from the terminal.

To clone a repo or open a pull request with GitHub CLI (the gh command), finish three jobs: install from the official channel, run gh auth login, then gh repo clone or gh pr create.

Follow cli.github.com instead of guessing package names. The queries are how to install GitHub CLI, gh auth login, and create a PR with gh. Docs: cli.github.com and cli.github.com/manual/.

ghOfficial command name
authLogin before API calls
PRCreate from the terminal

Install the official binary for your OS

macOS and Windows

macOS: brew install gh. Windows: winget install --id GitHub.cli, or Scoop / Chocolatey. Then run gh --version.

Linux

Follow the distro repo steps on cli.github.com for Debian, Ubuntu, Fedora, and others. Do not grab a random third-party deb. If Homebrew is blocked, use the official release packages.

StepCommandWatch for
Sign ingh auth logingithub.com vs Enterprise; HTTPS vs SSH; browser vs token
Checkgh auth statusAccount, protocol, and whether the token is still valid
Clonegh repo clone owner/repoPrivate repos need access; SSO orgs need an extra grant
Open a PRgh pr createBranch must be pushed; --fill or write title and body

Install, log in, clone or open a PR

  1. 01
    Install and confirm the version

    Pick the package manager on the official page. gh --version should print a version. If the command is missing, fix PATH; do not mix an old third-party gh script.

  2. 02
    Run gh auth login

    Choose GitHub.com (or the Enterprise host your admin gave you). HTTPS is fine for daily use; pick SSH if a key is already on the account. With a browser, choose Login with a web browser, copy the one-time code, finish at github.com/login/device. Headless: paste a PAT.

  3. 03
    Clone one repository

    In the target directory run gh repo clone owner/repo. A .git folder should appear. If a private clone fails, check gh auth status and org SSO.

  4. 04
    Create a PR from the current branch

    After commits are pushed, run gh pr create at the repo root. Fill title and body, or use gh pr create --fill. Open the returned URL and check the diff.

gh --version
gh auth login
gh auth status
gh repo clone owner/repo
cd repo
# After you commit and push the current branch:
gh pr create --title "Fix login timeout" --body "Repro and fix."
Is a browser login required?
No. The official wizard accepts a personal access token. CI and headless hosts use a token or the GH_TOKEN environment variable. Do not commit it.
HTTPS or SSH?
If a GitHub SSH key is already on the account, choose SSH so later git commands use that key. Otherwise choose HTTPS and let gh configure the credential helper.
pr create cannot find the repo or is denied?
Confirm you are in a git repo, the remote is GitHub, the branch is pushed, and the account can write that repo. SSO orgs need the org enabled on the grant.
Does install replace a shared diagram?
No. This is GitHub’s terminal client. When the meeting is the same diagram, open sitdraw.

Log in before you touch the repo

Until gh auth status is clean, do not treat a failed clone as a network outage. Most failures are account, SSO, or protocol mismatch.

Start the picture