Skip to content
Latchkey

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-token

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →