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/.
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.
| Step | Command | Watch for |
|---|---|---|
| Sign in | gh auth login | github.com vs Enterprise; HTTPS vs SSH; browser vs token |
| Check | gh auth status | Account, protocol, and whether the token is still valid |
| Clone | gh repo clone owner/repo | Private repos need access; SSO orgs need an extra grant |
| Open a PR | gh pr create | Branch must be pushed; --fill or write title and body |
Install, log in, clone or open a PR
- 01Install and confirm the version
Pick the package manager on the official page.
gh --versionshould print a version. If the command is missing, fix PATH; do not mix an old third-partyghscript. - 02Run 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.
- 03Clone one repository
In the target directory run
gh repo clone owner/repo. A.gitfolder should appear. If a private clone fails, checkgh auth statusand org SSO. - 04Create a PR from the current branch
After commits are pushed, run
gh pr createat the repo root. Fill title and body, or usegh 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_TOKENenvironment 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.