Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Git Users On Same Machine

Tags:

git

multi-user

Our team shares a MacBook which everybody uses from time to time with one account on it, so we're all on the some login. To commit our code changes we're using SmartGitHg 4.5 (current Git version installed is 1.8.3.2). Since these commits can get a little messy, I'm looking for a setup/config solution to commit under the right name, because if I leave the userdata in Git's global config empty, I'm automatically committing under the name 'developer' (which is the account name of our machine) even though I'm always getting asked for credentials when committing/pushing.

So maybe someone has a good idea how to set this up so that one just has to put in the credentials when committing/pushing/pulling. Maybe using the OSX keychain could be a way?

like image 558
DenverCoder21 Avatar asked Sep 17 '13 09:09

DenverCoder21


People also ask

Can you have two Git accounts one computer?

Step 1 : Create SSH keys for all accounts. Step 2 : Add SSH keys to SSH Agent. Step 3 : Add SSH public key to the Github. Step 4 : Create a Config File and Make Host Entries.

Can GitHub desktop handle multiple accounts?

Contributing to two accounts using HTTPS and SSHIf you contribute with two accounts from one workstation, you can access repositories by using a different protocol and credentials for each account. Git can use either the HTTPS or SSH protocol to access and update data in repositories on GitHub.com.

Can you have 2 GitHub accounts?

For most developers, there may be a need to run multiple GitHub accounts on one computer. For instance, you can run an Organization's GitHub account and another one for your personal projects all on the same computer. In this article, you will learn how to use multiple SSH keys for different GitHub accounts.


2 Answers

Make a repository clone for each developer on mac, and set user.name and user.email config variable for each clone (project level property). So, in this case each developer have to use own project (just different directories).

To set project level property execute (current directory should be the root of the project):

git config user.name "User Name"
git config user.email "UserEmail@Host"

UPDATE Also if the only reason you are using the same login for different developers is disk space, you can create one clone in /Users/Shared/, configure user.name and user.email variables in $HOME/.gitconfig and voila!

like image 194
4ndrew Avatar answered Oct 14 '22 22:10

4ndrew


If you don't have enough disk space for separate clones, you can try the following:

Use differente logins and write a script that changes the username and email on login.

OR (if you really want to use one account only)

Write a script that asks after every login for the username and email. That way nobody can forget to change the username and email.

like image 39
functionpointer Avatar answered Oct 14 '22 22:10

functionpointer