Git credentials helper with path matching
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2020-06-04 09:58:41 +02:00
go.mod Initial 2020-06-04 09:06:30 +02:00
LICENSE LICENSE 2020-06-04 09:27:57 +02:00
main.go Consider URLs with path as last resort 2020-06-04 09:51:33 +02:00
README.md Mention prefix earlier 2020-06-04 09:58:41 +02:00

git-credential-store-path

This is a Git credential helper that can serve different credentials based on the repo path prefix. It's useful when you have multiple GitHub users with access to different organizations.

Installation

Make sure that the git-credential-store-path binary is in your $PATH.

Add the following to your ~/.gitconfig:

[credential]
    helper = store-path
    useHttpPath = true
[url "https://github.com/"]
    insteadOf = git@github.com:

The URL replacement is to force usage of HTTPS instead of SSH, as the credentials helper can't assist with SSH connections.

On mac you may also need to run git config --system --unset credential.helper to avoid the default osxkeychain caching the login, as it does not care about the path.

Usage

The helper reads ~/.git-credentials in the same way as the regular git-credentials-store helper and could be used as a drop in replacement. In addition, it also does matching on path prefixes and uses the first matching entry. For example, the following .git-credentials file:

https://org1-user:someapikey@github.com/Org1/
https://org2-user:someapikey@github.com/Org2/
https://myuser:someapikey@github.com

Operations on a repository Org1/foo will use the org1-user credentials, operations on Org2/bar will use the org2-user credentials, and all other repos will use myuser.