Martin Martin - 19 days ago 5
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
Repo-1
.

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

Let's call that user
User-1
.

I created SSH keypair, everything fine, works nice.




I made ANOTHER repository on GitHub, let's call it
Repo-2
.

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

Now - I want to clone from
Repo-1
as the
User-2
(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
User-2
? And then, from THAT identity, clone from Repo-1, make some change, and then push to
Repo-1
?

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

Moe Moe
Answer

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.

Comments