Skip to content
Advertisement

Save Multiple Password Accounts for Git?

I know it’s a bit of a pain to do, but I have multiple accounts for my personal accounts and work accounts. I generate tokens for these accounts so they have restricted access and I don’t have to use my actual password so it is more secure. The problem I have is that there doesn’t seem to be a very good way to store these passwords for multiple accounts. This applies for both Windows and Linux. The “easiest” way I found was just to have multiple user accounts on the system, which isn’t that convenient. Otherwise if you have one repo and you try and set the user using git config user.name etc, it’ll use the wrong password/account anyways for that repo.

Is there an easier or better way to go around this? To have multiple passwords saved for git and just be able to choose the account you want to use for the repo and have it just work?

Advertisement

Answer

You might consider using a credential helper like the recent (July 2020) GCM Core, announced by GitHub.

Git Credential Manager Core (GCM Core) is a secure Git credential helper built on .NET Core that runs on Windows and macOS.
Linux support is planned, but not yet scheduled.

For Linux, in the meantime, you can use the Java GCM.
(see last section below)

In both instance, the usage is the same: you can cache credentials (like your token) for a given URL.


Update Sept. 2020 (2+ months later) for Linux: microsoft/Git-Credential-Manager-Core issue 135 mentions, From GitHubber Matthew John Cheetham:

We have a pre-release of a GCM Core that supports Linux! 🥳

At the moment we provide a Debian package, and a tarball of the git-credential-manager-core single binary.
The .deb is currently unsigned and not uploaded anywhere except on GitHub.
We are in the process of getting package signing set up and will be publishing it to an official Microsoft feed (so you’ll be able to use apt-get!).
Currently the pre-built binaries are only provided for 64-bit Intel processors.

See more at Credential stores on Linux

There are currently three options for storing credentials that Git Credential Manager Core (GCM Core) manages on Linux platforms:

  • freedesktop.org Secret Service API
  • GPG/pass compatible files
  • Plaintext files

Update Aug. 2021: issue 135 is now closed by Matthew John Cheetham (GitHub staff):

Closing this issue as GCM Core can now run on Linux distributions.
For further issues/bugs, or support for more distributions please open new issues. Thanks!

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement