hickford / git-credential-oauth

A Git credential helper that securely authenticates to GitHub, GitLab and BitBucket using OAuth.
Apache License 2.0
417 stars 14 forks source link

Possible to specify credential helper as an env var? #43

Closed hydrajump closed 9 months ago

hydrajump commented 9 months ago

Is it possible to temporarily specify git-credential-oauth as the credential helper like GIT_SSH_COMMAND, but for HTTPS?

I'd like to be able to do a one-time similar to this:

GIT_HTTPS_COMMAND=git-credential-oauth command

At the moment I'm creating the .gitconfig and then deleting the file. It works, but thought I'd ask if there's a better way :)

hickford commented 9 months ago

You can specify any Git configuration setting temporarily following https://git-scm.com/docs/git#Documentation/git.txt--cltnamegtltvaluegt

git -c credential.helper=oauth push

or ignoring ignoring other credential helpers:

git -c credential.helper= -c credential.helper=oauth push

May I ask why you want to do this? https://xyproblem.info/

More convenient would be to set Git configuration specific to one repository:

git config --local credential.helper=oauth

or specific to one host:

git config --global credential.https://example.com.helper=oauth
hydrajump commented 9 months ago

Thank you @hickford! Your first command worked :) The reason I wanted to do this without creating a .gitconfig is that I'm running this on a host that is diskless and I wanted to be able to use OAUTH instead of creating a GitHub personal access token.

hickford commented 9 months ago

Better surely to also configure a storage helper such as cache so you don't have to reauthenticate on each command?

git -c credential.helper="cache --timeout 3600" -c credential.helper=oauth push

Equivalently

[credential]
helper = cache --timeout 3600
helper = oauth

Equivalently

git config --global --add credential.helper "cache --timeout 3600"
git config --global --add credential.helper oauth
hydrajump commented 9 months ago

Just wanted to thank you again! This has worked very well in the last week :)