0

Is there a way to get the username and password for GitHub, when they were previously cached by git with the credential helper on a Mac? I think hub already does it, but I don't know how.

The problem is that I want to call the GitHub API with the credentials in a script of mine, and I don't want to ask the user every time because they might get tired of doing it.

Eric Brandwein
  • 861
  • 8
  • 23

2 Answers2

2

You can store them permanently using:

git config credential.helper store

or if you want to store them for certain duration, use

git config --global credential.helper "cache --timeout=60000"
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

A very detailed answer (and a full one) can be found here.
This is the very short brief of it so you should read the full one above.

First of all its much better to use ssh keys instead of username password so you will not be prompt for those again.

If you still wish to use username/password pair you need to set the credential.helper flag.

https://www.kernel.org/pub/software/scm/git/docs/gitcredentials.html

From the git config documentation:

credential.helper Specify an external helper to be called when a username or password credential is needed; the helper may consult external storage to avoid prompting the user for the credentials. Note that multiple helpers may be defined. See gitcredentials(7) for details.

credential.useHttpPath When acquiring credentials, consider the "path" component of an http or https URL to be important. Defaults to false. See gitcredentials(7) for more information.

credential.username If no username is set for a network authentication, use this username by default. See credential..* below, and gitcredentials(7).

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167