Martin Martin - 1 year ago 68
Git Question

Switch between user identities in one Git on one computer

I'm a Git/Github newbie, forgive me if this is an elementary question, I might have not got the priciples right just yet (primary source: ProGit book). But I keep stumbling throughout the book, can't figure this out. Anyway...

I have ONE repository on GitHub, let's call it

I want to first access that repository as a default Git user.

Let's call that user

I created SSH keypair, everything fine, works nice.

I made ANOTHER repository on GitHub, let's call it

I didn't make any changes in local Git, on my laptop. No configurational changes, nothing.

Now - I want to clone from
as the
(but from the same laptop).

First of all: is this at all possible to do?

Can local Git on one single laptop switch between "user accounts" and present itself as
? And then, from THAT identity, clone from Repo-1, make some change, and then push to

If possible, how on Earth do I do that? Thanx in advance to whomever spares a line...

Moe Moe
Answer Source

You have your global .gitconfig where you already configured your SSH Keys/User Information. The global .gitconfig is overridden by a local gitconfig - the file "config" in your .git folder (if it does not exist you might have to create it). This website describes the process for Username and Emailadress but you can use every option avaliable.

For example you can copy the .gitconfig file into the .git folder (and rename it to "config") and just change the lines you want to change (probably github.user and github.token) or you create a new file with just the two lines in it.

If you prefer the command line "git config" you can avoid all the file moving stuff by omitting the "--global" option.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download