Skip to content

Provide a convenient way to add gh cli as a git credential helper #3796

Closed

Description

@jongio

Describe the feature or problem you’d like to solve

Right now, I have to google and trial and error to get the gh cli wired up as a git credential helper.

This command works:

git config --global 'credential.https://github.com.helper' ''
git config --global --add 'credential.https://github.com.helper' '!gh auth git-credential'

But I would prefer this be baked into the cli.

Proposed solution

Something like:

gh auth setup-git-credential-helper

Which would execute the commands above or the appropriate commands for a given os/arch combination.

Additional context

Add any other context like screenshots or mockups are helpful, if applicable.

azsdke2e
azsdke2e2

Activity

  1. added
    enhancement
    on Jun 7, 2021
  2. mislav commented on Jun 10, 2021

    @mislav
    Contributor

    Thanks for the suggestion! This is a good idea, as I often find myself suggesting these manual instructions to our users 👍

  3. added
    help wanted
    on Jun 22, 2021
  4. despreston commented on Jul 14, 2021

    @despreston
    Contributor
  5. vilmibm commented on Jul 16, 2021

    @vilmibm
    Contributor

    @despreston yup, that is the idea.

  6. mikeboiko commented on Aug 25, 2021

    @mikeboiko

    Thanks for the suggestion! This is a good idea, as I often find myself suggesting these manual instructions to our users +1

    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.

  7. jongio commented on Aug 26, 2021

    @jongio
    Author

    @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!

  8. mikeboiko commented on Aug 26, 2021

    @mikeboiko

    @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!

    Great idea! I searched the following in google:

    • how to use gh in .gitconfig
    • how to use gh as credentials in .gitconfig
    • using gh with git credential
    • how to push from github-cli
  9. jongio commented on Aug 26, 2021

    @jongio
    Author

    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!

  10. despreston commented on Aug 26, 2021

    @despreston
    Contributor

    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.

  11. mislav commented on Aug 30, 2021

    @mislav
    Contributor

    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.

  12. added 3 commits that reference this issue on Aug 31, 2021
    ed3d19f
    d35b943
    2c41882
  13. jongio commented on Sep 7, 2021

    @jongio
    Author

    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!

  14. gibfahn commented on Oct 1, 2021

    @gibfahn

    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)).

  15. sjackman commented on Mar 11, 2022

    @sjackman
    [credential "https://github.com/"]
    	helper = 
    	helper = !/usr/local/bin/gh auth git-credential
    [credential "https://gist.github.com/"]
    	helper = 
    	helper = !/usr/local/bin/gh auth git-credential

    What's the reason for the empty value in helper =?

    git config --global credential.helper '!gh auth git-credential' worked for me FWIW.

  16. mislav commented on Mar 11, 2022

    @mislav
    Contributor

    @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.

  17. elyobo commented on Sep 9, 2022

    @elyobo

    Just wanted to say that this is an excellent feature, thanks folks.

  18. akwotom commented on May 31, 2023

    @akwotom

    This is 2023, and gh auth setup-git isn't working. It returns no output, and changes nothing.

  19. mislav commented on May 31, 2023

    @mislav
    Contributor

    @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.

  20. locked as resolved and limited conversation to collaborators on May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions