You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a convenient way to add gh cli as a git credential helper #3796
@mikeboiko - Could you do me a favor and comment with all of the google search terms you used to try to find this info? If you post them here then they will be indexed for the next dev to find it faster. Thanks!
@mikeboiko - Could you do me a favor and comment with all of the google search terms you used to try to find this info? If you post them here then they will be indexed for the next dev to find it faster. Thanks!
What is the purpose of the git auth git-credential command now? Is that being used for anything other than what OP is asking for? Wonder if it makes sense to refactor git auth git-credential to do what this issue is asking for.
gh auth git-credential command was designed to be used as a git credential helper, i.e. to be invoked and used entirely from a git process. The user should never have to directly interface with this command; that's why it's "hidden".
I would leave the git-credential command as-is and create a new command to set up git with gh as a credential helper. Something like:
$ gh auth setup-git
#=> writes configuration to `~/.gitconfig`
For simplicity, I imagine that the command should be non-interactive. There is now a question for which GitHub hosts should the command set up a credential helper? I would propose that all hosts that gh is currently authenticated with should be covered. Additionally, there could be a setup-git --hostname flag to override that.
Reacted by Des Preston, Shverse, skippyelvis and Maru
As part of this, it would be great for the docs for this feature to note that gh will act as its own credential helper on systems where there isn't one by default (as @mislav explained in #2449 (comment)).
@sjackman The blank line is intentional to break the chain of previously configured global helpers when handling authentication for these hosts. Otherwise, git would have used a whole stack of each configured credential helper, copying the tokens between them, and we didn't want that for github.com since it could make it hard to debug for the user.
@akwotom To see what setup-git does under the hood, activate the verbose mode:
GH_DEBUG=1 gh auth setup-git
You should see that it invokes git config --global to edit global git configuration (usually in ~/.gitconfig). If there are any bugs with this, you are welcome to open a new issue and provide more information about your circumstances.
Activity
mislav commentedon Jun 10, 2021
Thanks for the suggestion! This is a good idea, as I often find myself suggesting these manual instructions to our users 👍
despreston commentedon Jul 14, 2021
i.e. expose this as a new command? https://github.com/cli/cli/blob/trunk/pkg/cmd/auth/shared/git_credential.go#L58 If that's all there is, I'd be happy to take this.
vilmibm commentedon Jul 16, 2021
@despreston yup, that is the idea.
mikeboiko commentedon Aug 25, 2021
Thank you all! It took me a good half an hour of googling to stumble upon this command.
I would imagine most git & GitHub users could benefit from it.
jongio commentedon Aug 26, 2021
@mikeboiko - Could you do me a favor and comment with all of the google search terms you used to try to find this info? If you post them here then they will be indexed for the next dev to find it faster. Thanks!
mikeboiko commentedon Aug 26, 2021
Great idea! I searched the following in google:
jongio commentedon Aug 26, 2021
Thanks. I also added to my blog post that led to filing this issue https://blog.jongallant.com/2021/06/codespaces-gh-cli-git-credentials/
Hopefully this helps get people here!
despreston commentedon Aug 26, 2021
What is the purpose of the
git auth git-credentialcommand now? Is that being used for anything other than what OP is asking for? Wonder if it makes sense to refactorgit auth git-credentialto do what this issue is asking for.mislav commentedon Aug 30, 2021
gh auth git-credentialcommand was designed to be used as a git credential helper, i.e. to be invoked and used entirely from agitprocess. The user should never have to directly interface with this command; that's why it's "hidden".I would leave the
git-credentialcommand as-is and create a new command to set up git with gh as a credential helper. Something like:$ gh auth setup-git #=> writes configuration to `~/.gitconfig`For simplicity, I imagine that the command should be non-interactive. There is now a question for which GitHub hosts should the command set up a credential helper? I would propose that all hosts that gh is currently authenticated with should be covered. Additionally, there could be a
setup-git --hostnameflag to override that.feat(3796): add cmd for setting up gh-cli as git cred helper
feat(3796): add cmd for setting up gh-cli as git cred helper
feat(3796): add cmd for setting up gh-cli as git cred helper
jongio commentedon Sep 7, 2021
Just a heads up that I created a GitHub CLI extension for this - just as an experiment with CLI extensions
https://github.com/jongio/gh-setup-git-credential-helper
The extension also clears the GITHUB_TOKEN env var and runs
gh auth login.I'll move the extension to the new setupgit cmd once it is ready. Looking forward to it!
gibfahn commentedon Oct 1, 2021
As part of this, it would be great for the docs for this feature to note that gh will act as its own credential helper on systems where there isn't one by default (as @mislav explained in #2449 (comment)).
sjackman commentedon Mar 11, 2022
What's the reason for the empty value in
helper =?git config --global credential.helper '!gh auth git-credential'worked for me FWIW.mislav commentedon Mar 11, 2022
@sjackman The blank line is intentional to break the chain of previously configured global helpers when handling authentication for these hosts. Otherwise, git would have used a whole stack of each configured credential helper, copying the tokens between them, and we didn't want that for
github.comsince it could make it hard to debug for the user.elyobo commentedon Sep 9, 2022
Just wanted to say that this is an excellent feature, thanks folks.
apparently the blank lines mean something cli/cli#3796 (comment)
akwotom commentedon May 31, 2023
This is 2023, and
gh auth setup-gitisn't working. It returns no output, and changes nothing.mislav commentedon May 31, 2023
@akwotom To see what
setup-gitdoes under the hood, activate the verbose mode:You should see that it invokes
git config --globalto edit global git configuration (usually in~/.gitconfig). If there are any bugs with this, you are welcome to open a new issue and provide more information about your circumstances.