List git credentials from credential helper
Asked Answered
D

3

11

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

Descender answered 4/8, 2020 at 17:43 Comment(4)
Do you have this file ~/.git-credentials ?Expositor
No such file or dirDescender
Ahh you are using cache method. cache Cache credentials in memory for a short period of time. If you are looking towards storing on disk you should use store method instead.Expositor
Yes memory I don't want to change I just want to see the credsDescender
E
18

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
Expositor answered 4/8, 2020 at 19:18 Comment(0)
S
8

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.

Sherikasherill answered 4/8, 2020 at 23:51 Comment(0)
F
0

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.

Florance answered 18/7, 2023 at 18:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.