danielrvt
danielrvt

Reputation: 10916

Multiple git credentials for same context

Is there a way to use multiple credentials for the same context?

Something like this:

[credential "https://example.com"]
    username = me
    username = me2
    username = me3

What can I do if for example I'm working with multiple organizations all of them using bitbucket? Or if I have a personal and a work bitbucket accounts?

Upvotes: 0

Views: 507

Answers (2)

bk2204
bk2204

Reputation: 76409

There's a Git config option called credential.useHttpPath. This forces the credential helper to store and read credentials independently based on the path, but only on the whole path. This allows you to use separate credentials for different repositories, at the expense of having to specify credentials for each repository.

For example, you could write something like the following:

[credential "https://bitbucket.com"]
    useHttpPath = true

and then let the credential helper prompt you for the username and password for each repo.

Unfortunately, there is no way to match on only part of the path unless the credential helper you're using has some external way to specify that.

Upvotes: 1

Xetius
Xetius

Reputation: 46774

This sounds like what the .mailmap file is for.

If you add this at the root of the repository, then you should be able to map your username to whatever email address you want.

Disclaimer: I've not used this myself, so cannot elaborate on use, but I believe it will help you here

Upvotes: 0

Related Questions