Save Multiple Password Accounts for Git?
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! /p>
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 useapt-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!
How can I save username and password in Git?
Attention: This method saves the credentials in plaintext on your PC's disk. Everyone on your computer can access it, e.g. malicious NPM modules.
Run
git config --global credential.helper store
then
git pull
provide a username and password and those details will then be remembered later. The credentials are stored in a file on the disk, with the disk permissions of "just user readable/writable" but still in plaintext.
If you want to change the password later
git pull
Will fail, because the password is incorrect, git then removes the offending user+password from the ~/.git-credentials
file, so now re-run
git pull
to provide a new password so it works as earlier.
Multiple GitHub accounts on the same computer?
All you need to do is configure your SSH setup with multiple SSH keypairs.
This link is easy to follow (Thanks Eric):
http://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574
Generating SSH keys (Win/msysgit):
https://help.github.com/articles/generating-an-ssh-key/
Relevant steps from the first link:
Generate an SSH-key:
ssh-keygen -t ed25519 -C "john@doe.example.com"
Follow the prompts and decide a name, e.g.
id_ed25519_example_company
.Copy the SSH public-key to GitHub from
~/.ssh/id_ed25519_doe_company.pub
and tell ssh about the key:ssh-add ~/.ssh/id_ed25519_doe_company
Create a
config
file in~/.ssh
with the following contents:Host github-doe-company
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_doe_companyAdd your remote:
git remote add origin git@github-doe-company:username/repo.git
or change using:
git remote set-url origin git@github-doe-company:username/repo.git
Also, if you're working with multiple repositories using different personas, you need to make sure that your individual repositories have the user settings overridden accordingly:
Setting user name, email and GitHub token – Overriding settings for individual repos
https://help.github.com/articles/setting-your-commit-email-address-in-git/
Note:
Some of you may require different emails to be used for different repositories, from git 2.13 you can set the email on a directory basis by editing the global config file found at: ~/.gitconfig
using conditionals like so:
[user]
name = Default Name
email = defaultemail@example.com
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig
And then your work-specific config ~/work/.gitconfig
would look like this:
[user]
name = Pavan Kataria
email = pavan.kataria@example.com
Thank you @alexg for informing me of this in the comments.
How to store multiple PATs/passwords for use by git?
Any credential helper should follow the same process.
But if you have multiple account/password for the same domain (say github.com for instance), then you need to change your remote URL
cd /path/to/my/local/repo1
git remote set-url origin https://user1@github.com/user1/myRepo1
^^^^^^
cd /path/to/my/local/repo2
git remote set-url origin https://user2@github.com/user1/myRepo2
^^^^^^
That way, the credential helper will differentiate your different account.
Since gcm core is a bit fineky to install, test it first with the classic libsecret-based helper.
GitHub: Separate credentials for two accounts on Windows
The conditional include that I detail here is only for commit authorship (user.name/email).
This has nothing to do with authentication (credentials: username/password)
Those are probably cached in a credential manager (like the linux osx-keychain)
Check the output of:
git config credential.helper
If you can, use instead SSH keys per environment, as I illustrate there: then you can easily maintain different identities for the same remote repo (github.com)
Note: the GCM (Git Credential Manager) installed alongside Git for Windows does not, as stated in issue 363, support multiple users per Uri.
Multiple Github Accounts With Git In Windows
Clearing the git entries in the windows credential manager did not resolve this issue.
If you are using ssh URL (git@github.com:<user>/<repo>
), the credential manager is not involved: it provides credentials for https://
URLS only.
Use git for the first time which asks for github credentials when pushing to a repository.
That would be the case only if the remote origin URL is an https one.
So the goal would be to push changes to multiple github accounts without having to do things like temporarily specify the ssh key to use.
That is done through an ssh config file: see as practical examples:
- "How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account?"
- "How to set up authentication for two separate GitHub accounts from same ssh client?"
From the edit
Host user1
HostName github.com
User git
IdentityFile ~/.ssh/iser1_key <<====
Host user2
HostName github.com
User git
IdentityFile ~/.ssh/user1_key <<==== same key!? Meaning same user!
you cannot expect push as user2, if the SSH config for user2 entry refers to user1 private key.
How can I have multiple git accounts on a single development machine?
You can store your credentials in each project using.
git config credential.helper store
git push origin HEAD
write user and password
Go to the project folder and type the git commands.
Can I specify multiple users for myself in .gitconfig?
You can configure an individual repo to use a specific user / email address which overrides the global configuration. From the root of the repo, run
git config user.name "Your Name Here"
git config user.email your@email.com
whereas the default user / email is configured in your ~/.gitconfig
git config --global user.name "Your Name Here"
git config --global user.email your@email.com
Related Topics
Ubuntu/Fedora: How to Add Applications in The Menus
Linux/Unix Socket Self-Connection
How to Create a Core File for My Crashed Program
How to Export a Symbol from an External Module
Tickless Kernel, Isolcpus,Nohz_Full,And Rcu_Nocbs
What Are The Lowest Possible Permissions for Typo3
Installing Ffmpeg on Amazon Linux - Cpp, Gcc & Libstdc++ Dependancies
Need Explanation on Pri Standard Format Specifier for Ps - Possible Bug in Documentation
How to Log from a Non-Root Debian Linux Daemon
Initramfs Built into Custom Linux Kernel Is Not Running
Jenkins Running at Very High CPU Usage
Why Does The Linker Modify a -Defsym "Absolute Address"
Rtnetlink Answers: No Such File or Directory