Switch between user IDs in one Git on one computer

I have ONE repository on GitHub , call him Repo-1 .

I want to first access this repository as the default Git .

Call this user User-1 .

I created SSH keypair , everything is fine, works fine .




I made an OTHER repository on GitHub , call him Repo-2 .

I made no changes to the local git on my laptop. No configuration changes, nothing.

Now - I want to clone from Repo-1 as User-2 (but from the same laptop ).

First of all: is it even possible?

Can local Git on the same laptop switch between "user accounts" be present as User-2 ? And then, from this identity, a clone from Repo-1, make some changes, and then click on Repo-1 ?

If possible, how to do it?

+59
git github user
Feb 19 '12 at 7:18
source share
2 answers

You have a global .gitconfig where you already configured your SSH keys / user information. The global .gitconfig is overridden by the local gitconfig - the "config" file in your .git folder (if it does not exist, you may need to create one).

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

If you prefer the command line "git config", you can avoid all file transfers by eliminating the "--global" option.

+55
Feb 19 '12 at 8:44
source share

You need to determine if you really have two ssh key pairs or two letters that you want to use. The ssh key is associated with accounts as described here .

The ssh key (in particular the private key) basically gives your client git permission to connect to github and therefore push permission. This is separate from the user ID, which is only the email address in your commit messages.

If you have two ssh keypairs, each associated with a single account, follow these instructions to create the ~/.ssh/config file. The key part is to use a different ssh psuedo-host for each account:

 # Default GitHub user (joe) Host github.com HostName github.com User git IdentityFile /Users/joe/.ssh/id_rsa # Client user (client) Host github-client HostName github.com User git IdentityFile /Users/joe/.ssh/id_rsa_client 

Then you use two corresponding remotes:

 git clone git@github.com:joe/my_repo.git 

and

 git clone git@github-client:client/his_repo.git 

If you just want to use two emails, you can simply give each clone a separate .git/config with the desired [user] settings.

+43
Feb 19 '12 at 9:16
source share



All Articles