this is a git credential helper that only reads from the credential store, and never writes to it.
in a word, it is a drop-in replacement for git-credential-store
that only handle get
action, and silently ignore store
and erase
.
it exists because the git built-in credential helper store
will always write back to the credential store file.
which will cause problem when you have different store config for both user personal token and organization personal token.
for example:
[credential "https://github.com/org-name/"]
helper = readonly --file ~/.git-credentials-org
[credential]
helper = readonly
if you use store
instead of readonly
, it will always write back to the credential store file,
which will cause problem after you use organization token,
it will write the organization token back to the user credential store file.
so you personal token (by default in ~/.git-credentials
) will be overwritten by the organization token.
due to both auth host name are the same.
go install github.com/ttys3/git-credential-readonly@latest
usage: `git-credential-readonly <get|store|erase>`
git config --global credential.helper readonly
the credential.helper config sequence is important, git will match against it until it get the matched credentials.
so organization specific token should goes first.
# organization specific token
[credential "https://github.com/your-org/"]
helper = readonly --file ~/.git-credentials-org
# https://git-scm.com/docs/gitcredentials#Documentation/gitcredentials.txt-useHttpPath
# uncomment below if you need match path by username or org name
# for example: repo path `foo/bar.git`, will match path by `foo`
#useHttpPath = true
# general personal token
[credential]
helper = readonly
[url "https://github.com/"]
insteadOf = [email protected]:
the credential files:
~/.git-credentials-org
:
https://username:[email protected]
~/.git-credentials
:
https://username:[email protected]
you can also use personal and org tokens in one file:
the config:
# github specific token
[credential "https://github.com/"]
helper = readonly --file ~/.git-credentials-org
# https://git-scm.com/docs/gitcredentials#Documentation/gitcredentials.txt-useHttpPath
# uncomment below if you need match path by username or org name
# for example: repo path `foo/bar.git`, will match path by `foo`
useHttpPath = true
the credential files:
~/.git-credentials-org
:
https://username:[email protected]/username
https://username:[email protected]/org-foo
https://username:[email protected]/org-bar
https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage#_a_custom_credential_cache