gh auth login

Three ways to auth

1 min read
Git GitHub CLI

gh auth is a really nice way to access your Github repos from the command line. But it has always confused me a little bit. I believe there are [three ways] you can auth with gh auth:

  • with an 1) environment variable or 2) stored token
    1. I believe if gh auth is run without the --with-token flag, it first checks for an environment variable (can be GH_TOKEN or GITHUB_TOKEN). If found, it uses that
    2. If no environment variable is found, it looks for a Github token stored credentials (Keychain (mac), libsecret (Linux) or Credential Manager (Windows)). If found, it uses that.
  • gh auth login (with no environment variable set and no stored token set)
    • uses the default method, web-based, which is really convenient
    • stores an auth token in the system credentials store
  • gh auth login --with-token
    • you can pass in a classic personal access token (must have repo, read:org and gist) in standard input
    • you can also pass in an environment variable here if you like with echo $GH_TOKEN | gh auth login --with-token