* Allow `gh auth git-credential` to authenticate GitHub Gist requests
When there are stored credentials for `example.com`, allow using them to
authenticate requests to `gist.example.com` as well.
* Fix writing out of credential config
* remove unneccessary function
* actually delete
Co-authored-by: nate smith <vilmibm@github.com>
Adds a new command `gh auth setup-git [<hostname>]` that sets up git to
use the GitHub 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 --replace-all '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.
Co-authored-by: Mislav Marohnić <mislav@github.com>
This keeps git operations working even when PATH is modified, e.g. `brew
update` will work even though Homebrew runs the command explicitly
without `/usr/local/bin` in PATH.
Additionally, this inserts a blank value for `credential.*.helper` to
instruct git to ignore previously configured credential helpers, i.e.
those that might have been set up in system configuration files. We do
this because otherwise, git will store the credential obtained from gh
in every other credential helper in the chain, which we want to avoid.
Before:
git config --global credential.https://github.com.helper '!gh auth git-credential'
After:
git config --global credential.https://github.com.helper ''
git config --global --add credential.https://github.com.helper '!/path/to/gh auth git-credential'