Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage multiple user configs in Git?

Tags:

git

I work with multiple Git remote repositories and each need different Git credentials (Name and Mail).

Is there any solution such as a script or best practices how to manage them?

I know about "config --local", but I don't want to set this variables manually everytime.

like image 763
MicTech Avatar asked Jan 08 '11 19:01

MicTech


1 Answers

It looks like just saying git config user.name (or user.email) in a particular repository, without specifying --global or --system would do the trick. The default is to set the configuration in the current repository, and you have to give it explicit options for it to write to your user-level or system-wide configuration instead.

I don't know how one would do this if you're freshly cloning repositories that need different configuration, though. Perhaps you could write a small script that wraps git clone to clone some repository, and then set the appropriate configuration based on whatever information? If you drop the script in /usr/lib/git-core named something like git-nclone, you can then run it as git nclone.

Edit: Since you don't want to manually set it every time, how about a clone wrapper that remembers the various sets you actually use, and lets you pick the appropriate one for the repository you're cloning. It could even have smart defaults based on where you're clone is coming from.

like image 97
Phil Miller Avatar answered Sep 20 '22 13:09

Phil Miller