Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@despreston
Copy link
Contributor

@despreston despreston commented Aug 31, 2021

Adds a new command gh auth setup-git [<hostname>] that sets up git to
use the GH CLI as a credential helper.

The gist is that it runs these two git commands for each hostname the
user is authenticated with.

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

If a hostname flag is given, it'll setup GH CLI as a credential helper
for only that hostname.

If the user is not authenticated with any git hostnames, or the user is
not authenticated with the hostname given as a flag, it'll print an
error and return a SilentError.

Closes #3796

@cliAutomation
Copy link
Collaborator

Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message.

@despreston despreston force-pushed the 3796-git-cred-helper branch 2 times, most recently from ed3d19f to d35b943 Compare August 31, 2021 14:52
@mislav mislav self-requested a review September 1, 2021 16:09
@mislav mislav self-assigned this Sep 1, 2021
Adds a new command `gh auth setup-git [<hostname>]` that sets up git to
use the GH CLI as a credential helper.

The gist is that it runs these two git commands for each hostname the
user is authenticated with.

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

If a hostname flag is given, it'll setup GH CLI as a credential helper
for only that hostname.

If the user is not authenticated with any git hostnames, or the user is
not authenticated with the hostname given as a flag, it'll print an
error and return a SilentError.

Closes cli#3796
@despreston despreston requested a review from a team as a code owner December 2, 2021 16:20
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

I've pushed some tweaks/fixes/simplifications, and this is good to go! Thank you 🚀

@mislav mislav enabled auto-merge (squash) December 2, 2021 16:30
@mislav mislav merged commit 94a640b into cli:trunk Dec 2, 2021
@despreston despreston deleted the 3796-git-cred-helper branch December 2, 2021 16:41
@VictorBatta VictorBatta mentioned this pull request Dec 4, 2021
@mfaani
Copy link

mfaani commented Sep 21, 2022

are you suppose to run this after gh auth login or before?

@mislav
Copy link
Contributor

mislav commented Sep 28, 2022

gh auth login interactive flow already includes step that asks if it's OK to let GitHub CLI set up Git authentication. If someone answers “Yes”, then running gh auth setup-git is not needed.

However, if someone had skipped that, then running gh auth setup-git after gh auth login is the way to go.

@eggplants
Copy link

Note that gh auth setup-git adds the following sections to ~/.gitconfig:

[credential "https://github.com"]
    helper =
    helper = !/path/to/gh auth git-credential
[credential "https://gist.github.com"]
    helper =
    helper = !/path/to/gh auth git-credential

vscode-remote-release will only override [credential], so you will not be able to perform git operations that require credentials of github.com/gist.github.com from the Dev Container terminal.

Ref: microsoft/vscode-remote-release#9252

I don't know whether it should be fixed with gh cli or vscode-remote-release...

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants