shamon shamsudeen
shamon shamsudeen

Reputation: 5848

List git credentials from credential helper

Seems like a simple problem but I can't find a solution, in my git config credentials stored in the cache(username and personal access token) the git config --list returns the credential info like this

credential.helper=cache

Is it possible to see the credentials from the cache, I tried the following three locations

  1. (repository_home) /.git/config - there is no info about the username and password

  2. ~/.gitconfig - file not found in the repo folder

Upvotes: 12

Views: 30575

Answers (3)

VonC
VonC

Reputation: 1323553

The Input/output format for git credential is documented here, and can be used with echo (one attribute) or printf (multiple attributes)

echo url=https://github.com/git/git.git | git credential fill
# or
printf "protocol=https\nhost=github.com"  | git credential fill

And that will work with any registered credential helper, whose list has been extended with Git 2.42 (Q3 2023):

See commit 4c9cb51 (08 Jul 2023) by M Hickford (hickford).
(Merged by Junio C Hamano -- gitster -- in commit d6e6722, 18 Jul 2023)

doc: gitcredentials: link to helper list

Signed-off-by: M Hickford

Link to community list of credential helpers.
This is useful information for users.

Describe how OAuth credential helpers work.
OAuth is a user-friendly alternative to personal access tokens and SSH keys.
Reduced setup cost makes it easier for users to contribute to projects across multiple forges.

gitcredentials now includes in its man page:

Available helpers

The community maintains a comprehensive list of Git credential helpers at https://git-scm.com/doc/credential-helpers.

OAuth

An alternative to inputting passwords or personal access tokens is to use an OAuth credential helper. Initial authentication opens a browser window to the host. Subsequent authentication happens in the background. Many popular Git hosts support OAuth.

Upvotes: 0

bk2204
bk2204

Reputation: 76409

It is possible for you to query a particular set of credentials from the credential helper, but there isn't a part of the credential helper protocol that allows you to query all credentials. In general, this is hard, because a credential helper can respond to all credentials that match a pattern, such as https://*.example.org or https://github.com/bk2204/*, and that pattern need not match any simple pattern that can be expressed (for example, the helper could have intimate knowledge about which repositories a user has access to based on LDAP).

For the cache credential helper, there isn't a way to enumerate those credentials.

If you want to look up the credentials for a particular URL, the easiest way to do that is like this:

echo url=https://github.com/git/git.git | git credential fill

That will print the credentials that any credential helper knows about. You can see more about the protocol in the gitcredentials(7) man page.

Upvotes: 9

Vijay
Vijay

Reputation: 888

From git-credential git credential fill could be helpful here, you need to input host and protocol details to get username and password.

$ git credential fill
protocol=https
host=example.com

Output:

protocol=https
host=example.com
username=bob
password=secret

Upvotes: 19

Related Questions