Skip to content

Select authenticated user via GH_USER env var #12145

@gringolito

Description

@gringolito

Describe the feature or problem you’d like to solve

I manage multiple GitHub accounts across several projects and must manually run gh auth switch to change identities or explicitly set a flag to choose which authenticated account to use. I often forget to switch, which leads to accidental operations under the wrong account and interrupts my workflow. I would like to set an environment variable in my current workspace to instruct/hint gh CLI which user it should use.

Proposed solution

When multiple users are authenticated, gh should respect an environment variable (e.g. GH_USER) to pick the active user non-interactively, similar to AWS CLI's AWS_PROFILE.

Additional context

$ gh auth status
github.com
  ✓ Logged in to github.com account gringolito (keyring)
  - Active account: false
  - Git operations protocol: https
  - Token: ************************************
  - Token scopes: **********************************

  ✓ Logged in to github.com account Filipe-Utzig (keyring)
  - Active account: true
  - Git operations protocol: https
  - Token: ************************************
  - Token scopes: **********************************
$ export GH_USER=gringolito
$ gh api /user | jq -r ".login"
gringolito
$ export GH_USER=Filipe-Utzig
$ gh api /user | jq -r ".login"
Filipe-Utzig

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIgh-authrelating to the gh auth commandpitchpitched internally for prioritisation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions