Command referencegh auth login
gh auth login command (Linux & Windows / GitHub CLI)
What it does
Authenticate the GitHub CLI with GitHub.com or GitHub Enterprise so other gh commands can run. When people search for gh auth login, they usually want practical GitHub CLI flags, safe examples, and how this subcommand fits everyday PR and repo workflows on Linux, Windows, and macOS. Syntax, options, and copyable examples are below.
Authenticate the GitHub CLI with GitHub.com or GitHub Enterprise so other gh commands can run.
Syntax
gh auth login [flags]
Common options
| Flag / option | Meaning |
|---|---|
| -h, --hostname | GitHub hostname (default github.com). |
| -p, --git-protocol | Prefer https or ssh for git operations. |
| -w, --web | Open a browser to complete login. |
| -s, --scopes | Additional OAuth scopes to request. |
| --with-token | Read a token from standard input (scripts only). |
Practical examples
Interactive login
gh auth login
Walks through host, protocol, and browser or token authentication.
Browser flow
gh auth login -w
Opens the browser to authorize the GitHub CLI app.
Prefer SSH
gh auth login -p ssh
Configures git remotes to use SSH after login.
Enterprise host
gh auth login -h github.example.com
Authenticates against a GitHub Enterprise Server hostname.
Common mistakes
- Pasting a personal access token into chat logs or committed scripts.
- Skipping login and wondering why later gh commands return HTTP 401.
Related commands
- gh auth statusShow which GitHub accounts are logged in and whether credentials are valid for each host.
- gh auth logoutRemove GitHub CLI authentication for a host or account from the local machine.
- gh configGet or set GitHub CLI configuration values such as git protocol and prompt behavior.
- gh repo cloneClone a GitHub repository to your machine using your authenticated gh settings.
- gh pr createCreate a pull request from the current branch with title, body, reviewers, and base branch options.
- gh pr mergeMerge a pull request using merge commit, squash, or rebase strategies.
- gitTrack source history and collaborate through distributed repositories.
- gh pr checkoutCheck out a pull request locally as a branch so you can build, test, or review the changes.
FAQ
What does gh auth login do in GitHub CLI?
Authenticate the GitHub CLI with GitHub.com or GitHub Enterprise so other gh commands can run.
Does gh auth login work on Windows and Linux?
Yes. The GitHub CLI (`gh`) runs on Linux, Windows, and macOS with the same subcommand syntax after you authenticate with `gh auth login`.
What is a practical gh auth login example?
Try `gh auth login` — Walks through host, protocol, and browser or token authentication.
Do I need a token in the command line for gh auth login?
Prefer `gh auth login` so credentials stay in the system keyring or secure storage. Avoid pasting personal access tokens into shell history.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.