How can I have multiple git accounts on a single development machine?
Solution 1
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.
Solution 2
By default, git is using a system-wide configuration file or the one stored at top of your home directory.
But you can also set a file .git/config
inside each repository, either by editing manually or using git config
. Inside, you may specify the following sections :
[user]
name = Your name
email = [email protected]
…
[credential "<your_project_hoster_url>"]
username = <username to log in with>
You can check git config in general or git credentials in particular for more information about it.
Solution 3
You can configure your user details per repository.
git config user.name 'Your Name'
git config user.email '[email protected]'
GitHub can be configured to recognise several ssh keys assigned to email addresses and send email messages to the corresponding ones when needed.
Solution 4
If you prefer https instead of the SSH key solutions, the following works on Windows at least for Github (and in connection with TortoiseGit using a credential manager):
- In your local repository (or while cloning), set the remote (origin) url to
https://[yourusername]@github.com/[org]/[repo].git
(The important part here is the [email protected] as this creates a git:https://[email protected]
entry in the Windows credential store that differs from the regular git:https://github.com
entry that holds the credentials for all "regular" remote urls)
In case you want to edit it for an existing repository via the repo/.git/config
file, this is something like
[remote "origin"]
url = https://[yourusername]@github.com/[org]/[repo].git
fetch = +refs/heads/*:refs/remotes/origin/*
- Additionally, set the
credential
anduser
properties in therepo/.git/config
file so your commits have the correct author:
[credential]
username = [Github-Username]
[user]
name = [Fullname]
email = [Email Address]
At your git remote operation (fetch, push etc.), you will be asked for authentication depending on your auth manager.
Ore0D3v
Updated on June 17, 2022Comments
-
Ore0D3v almost 2 years
I am trying to work simultaneously on more than one (two or three) GitLab (or even GitHub) projects on a single development machine. Because upon configuration the IDEs and the git service has the data of my primary user when I try to checkout or clone another project with a different username / password the system says either project is not found or I do not have permissions to do that.
How can I configure and use more than one git user on a single development machine?
-
choroba almost 6 yearsgit user can be configured per repository.
-
phd almost 6 yearsPossible duplicate of Multiple GitHub Accounts & SSH Config
-
Frax almost 6 yearsPossible duplicate of Multiple git user in single device
-
-
Ore0D3v almost 6 yearsthank you so much! I already granted the first as answer but all worked like a charm!
-
0andriy over 2 yearsWon't work if you have many remotes in one repo.
-
saulius2 almost 2 yearsThanks for the hint! Finally I found the culprit of Git using the wrong username from my
~\.git-credentials
(from the first line, but not from the second one). So I just set this setting locally:git config credential.username my-2nd-username
, and it worked fine. Thank you.