11

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?

DenverCoder21
  • 879
  • 3
  • 16
  • 34

2 Answers2

6

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!

Luke Stevenson
  • 10,357
  • 2
  • 26
  • 41
4ndrew
  • 15,354
  • 2
  • 27
  • 29
  • Thanks for your answer. This doesn't seem to be a very elegant way of doing it. Also, I think there isn't enough diskspace for this. Any other suggestions? – DenverCoder21 Sep 17 '13 at 09:52
  • I tried creating a .gitconfig file at the project level for the `user.name` and `user.email`, but when i do `git config --list` , i have 2 `user.name` and `user.email` values. How do you set git to only register the project level value? – dko May 08 '22 at 21:37
  • ^edit- I was making a file `.gitconfig` , not checking the file `.git/config` in the project directory... Fixed my issue! – dko May 09 '22 at 02:25
1

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.

functionpointer
  • 1,411
  • 1
  • 13
  • 18
  • The second solution sounds not too bad actually. Not very beaufitul, but practical nonetheless. Thanks! – DenverCoder21 Sep 17 '13 at 10:33
  • 1
    You literally asked for some sort of dirty solution. I mean, come on, you don't want to use multiple logins, or multiple repos. Whats left then? – functionpointer Sep 17 '13 at 11:48
  • I don't know, that's why I'm asking. Don't get me wrong, I'm fine with the solution you proposed and going to do it like that, thanks again. I was just hoping for some sort of Git/OSX keychain config that asks for credentials everytime you commit/push via SmartGit (or command line, doesn't matter) and actually uses them. The current situation is that SmartGit asks for credentials everytime, but if you don't set the credentials fixed in Git's config you get an anonymous commit. And if I knew there wasn't such a solution, I wouldn't have asked. ;) – DenverCoder21 Sep 17 '13 at 11:59