gh auth login Command Reference
Authenticate the GitHub CLI so later gh commands can call the API.
gh auth login signs the GitHub CLI in to a host. In CI you authenticate non-interactively with a token rather than the interactive web flow.
What it does
gh auth login establishes credentials for a GitHub host. Interactively it offers a browser or token flow; in automation you pipe a token to it or simply set GH_TOKEN, which gh reads directly without an explicit login.
Common flags and usage
- --with-token: read an auth token from stdin (non-interactive)
- --hostname HOST: target GitHub Enterprise Server
- --git-protocol https|ssh: protocol for git operations
- GH_TOKEN / GITHUB_TOKEN env var: gh uses it directly, no login needed
Example
shell
- name: Authenticate gh
run: echo "${{ secrets.GH_PAT }}" | gh auth login --with-tokenIn CI
The simplest path on GitHub Actions is to set env GH_TOKEN to the workflow token; gh then works with no login step. Use gh auth login --with-token when you need a different identity than the default GITHUB_TOKEN.
Key takeaways
- Pipe a token to gh auth login --with-token for non-interactive auth.
- Setting GH_TOKEN lets gh work with no explicit login step.
- Use --hostname for GitHub Enterprise Server targets.
Related guides
gh api Command ReferenceReference for gh api in CI/CD: call any REST or GraphQL endpoint with authentication handled, pass fields, pa…
gh repo clone Command ReferenceReference for gh repo clone in CI/CD: clone a repository with gh authentication, pass git clone flags after a…
gh secret set Command ReferenceReference for gh secret set in CI/CD: create or update Actions, environment, or Dependabot secrets non-intera…