15

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?

3

5 Answers 5

14

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks 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.
Fantastic!! I have been searching how to be able to talk to multiple git repos on the same machine, this works seamlessly with the [credential} tip key for me.
5

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.

Comments

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):

  1. 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/*
  1. Additionally, set the credential and user properties in the repo/.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.

Comments

3

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.

1 Comment

Won't work if you have many remotes in one repo.
1

Git multiple user config manager gum

Install

$ npm i -g @gauseen/gum

Example

$ gum list

Currently used name=gauseen [email protected]
┌────────────┬─────────┬─────────────────────────┐
│ group-name │    name │                   email │
├────────────┼─────────┼─────────────────────────┤
│    global  │ gauseen │ [email protected]       │
│    user1   │ li si   │ [email protected]          │
│    user2   │ wang er │ [email protected]        │
└────────────┴─────────┴─────────────────────────┘
$ gum use user1

Currently used name=li si [email protected]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.