I have 2 github accounts (work & personal) for which I want to store credentials in my Windows 10 (in secure way).
git config --global credential.helper manager
command sets only single username & password which conflicts between personal repo and work repo in my machine. Both repo are cloned using HTTPS.
I want to store and access different credentials probably based on repo username. Is it possible?
I know SSH is an option but I would like to know the way for HTTPS.
Just prefix the origin path with your username and @, like so: [email protected]/repo/reporepo. git This allows the Windows credential manager to store multiple logins.
You can use git-credential-store to store your passwords unencrypted on the disk, protected only by the permissions of the file system. You can check the credentials stored in the file ~/.git-credentials . For more information, visit git-credential-store - Helper to store credentials on disk. Save this answer.
The default path for the git credential store is $HOME/. git-credentials (or $XDG_CONFIG_HOME/git/credentials, if the previous location doesn't exist).
It is located at %UserProfile%\. git-credentials , which corresponds to C:\Users\<username>\.
On Bitbucket, you can add a username to the HTTPS URL of your remote:
https://[email protected]/path/repo.git
https://bitbucket.org/path/repo.git
Since the URL is technically different, you can add both your work and personal forks as remotes for the same repository if you want to. Issue #749 for the legacy Git Credential Manager suggests that the username-in-URL technique works on GitHub as well, but other repository hosts may not support it.
useHttpPath
More generally, you can use credential.useHttpPath
to split credential management for multiple repositories run by the same host. The quote below from the legacy Git Credential Manager documentation includes command-line suggestions for setting it on bitbucket.com
, but you can modify for your own purposes or take a look at the longer example text in the newer GCM Core docs.
useHttpPath
Instructs Git to supply the path portion of the remote URL to credential helpers. When path is supplied, the GCM will use the host-name + path as the key when reading and/or writing credentials.
Note: This option changes the behavior of Git.
Supports
true
orfalse
. Defaults tofalse
.git config --global credential.bitbucket.com.useHttpPath true
As rjmunro notes in the comments, you can drop --global
to use the path for only the current repo. If so, you may as well drop the hostname, too:
git config credential.useHttpPath true
This second method does not help if you want to log into the exact same repo with different credentials on a whim. (See legacy GCM #363.)
You could do it with a different helper e.g. git-credential-store which takes an optional parameter for a credential file path. You could set this in local config in each repo, with a different credentials file for each repository.
Alternatively use the suggestion in the link in @phd's comment which should work for Git Credential Manager For Windows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With