Skip to content

Add --account flag to git-credential helper - #13468

Closed
lkebin wants to merge 3 commits into
cli:trunkfrom
lkebin:get-credential-with-account
Closed

lkebin wants to merge 3 commits into
cli:trunkfrom
lkebin:get-credential-with-account

Conversation

@lkebin

@lkebin lkebin commented May 20, 2026 •

Copy link
Copy Markdown

Fixes #9111

To use specified account for git-credential:

~/.gitconfig:

[credential "https://github.com"]
	helper = !/opt/homebrew/bin/gh auth git-credential
	
[includeIf "gitdir:~/work"]
    path = ~/work/.gitconfig

~/work/.gitconfig:

[credential "https://github.com"]
	helper = !/opt/homebrew/bin/gh auth git-credential --account work-account

@lkebin
lkebin requested a review from a team as a code owner May 20, 2026 07:03
@lkebin
lkebin requested review from BagToad and Copilot May 20, 2026 07:03
@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed unmet-requirements and removed needs-triage needs to be reviewed labels May 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your pull request! Unfortunately, it doesn't meet the requirements for review:

  • None of the referenced issues have the help wanted label

Please update your PR to address the above. This PR will be automatically closed in 4 days if these requirements are not met.

Full contribution requirements
  1. Include a detailed description of what this PR does
  2. Link to an issue with the help wanted label (use Fixes #123 or Closes #123)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for selecting a specific configured GitHub account when gh auth git-credential get is used as a git-credential helper, addressing the inability to retrieve tokens for non-active accounts.

Changes:

  • Add --account flag to gh auth git-credential to request credentials for a specific username.
  • Use TokenForUser for account-scoped token lookup (including gist. host normalization).
  • Extend git-credential helper tests with --account scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/cmd/auth/gitcredential/helper.go Adds --account flag and token lookup path using TokenForUser
pkg/cmd/auth/gitcredential/helper_test.go Adds unit tests for --account behaviors
Comments suppressed due to low confidence (1)

pkg/cmd/auth/gitcredential/helper.go:130

  • In the --account path, a missing token results in a new error message (account %q not found...). Elsewhere in this helper, “no credentials available” cases return cmdutil.SilentError to avoid printing anything to stderr. To keep git-credential behavior consistent and quiet, consider returning cmdutil.SilentError here (and only error loudly for truly exceptional conditions).
		gotToken, _, tokenErr := cfg.TokenForUser(tokenLookupHost, opts.Account)
		if tokenErr != nil {
			return fmt.Errorf("gh auth git-credential: account %q not found on %s", opts.Account, lookupHost)
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/cmd/auth/gitcredential/helper.go
Comment thread pkg/cmd/auth/gitcredential/helper_test.go
lkebin added 2 commits May 20, 2026 15:13
- Exempt x-access-token username from --account mismatch check
- Add tests for --account with gist host and x-access-token username
@navayla777-dotcom

This comment was marked as spam.

@BagToad

BagToad commented May 22, 2026

Copy link
Copy Markdown
Member

Closing due to contribution guidelines (no help wanted label) + I don't think myself and the other maintainers have agreed on the approach for this problem space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team unmet-requirements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow gh auth git-credential get to get a token for non-active user

4 participants