There are three aspects to the second user.
1. GitHub Account
To use the GitHub web interface as another user (for example, a fork repository, send a transfer request, send comments), you need to log in to another account. *
Tip. Switching between accounts is a pain because you have to log out and sign up every time. You can log in to two accounts at the same time using a private browser window, another browser, or another browser profile.
2. SSH authentication
GitHub repository can be obtained via HTTPS or SSH. Both require authentication, which GitHub uses to implement permission levels . I will describe how to clone a repository with SSH configured for authentication as a second user.
Create a new SSH key using ssh-keygen -f KEYFILE , where KEYFILE is the path to the new key (e.g. ~ / .ssh / bob_rsa).
Add the SSH key to the GitHub account for the second user.
SSH needs to be configured to use ~ / .ssh / bob_rsa, but only when you are trying to clone the repository as a second user. That way, you can still clone the repositories as a regular user with the SSH key that you added to your regular GitHub account. Different configurations may be specified based on the host name, but for GitHub repositories, the host name is always github.com. To specify configurations for only some cloned repositories, add a host alias by adding the following to ~ / .ssh / config ( credit ):
# alias for github.com with a custom SSH key Host bob.github.com HostName github.com IdentityFile ~/.ssh/bob_rsa
I used the host name bob.github.com, but it can be any string.
Now you can clone the GitHub repository as a second user using the host name bob.github.com (or any host name that you used in the SSH configuration):
git clone git@bob.github.com :USER/PROJECT.git
If you clone a repository owned by your first user, that way, you wonβt be able to click on it until you add the second user as a collaborator .
Testing SSH Configuration
If you are having problems, check if SSH is working by running
ssh git@bob.github.com
(replace bob.github.com with the host name in the Host XXX line).
The first time you connect to GitHub via SSH, you should get a message like
The authenticity of host 'github.com (192.30.253.113)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)?
Type yes , then press ENTER . (For security, first verify that the fingerprint is listed on the GitHub SSH Keys page ).
If your configuration is correct and you added the SSH key to the second GitHub account by inserting the contents of the ~ / .ssh / bob_rsa.pub page on the SSH and GPG Keys page, you should see
PTY allocation request failed on channel 0 Hi USER! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.
USER must be the name of the second account.
If you also set up SSH access for your regular account, you can run
ssh git@github.com
and get the same message, but where USER is the name of your regular account.
3. Git Author Metadata
Git stores the author name and email address with each commit. For example, GitHub uses this information to display custom avatars in the commit history. It is trivial to deceive this information ( 1 , 2 ).
The author name and email address are usually stored in the global configuration file (~ / .gitconfig). You can override them based on each repository by doing the following in the repository directory:
git config --local user.name "NAME" git config --local user.email "EMAIL"
Replace NAME and EMAIL with the full name and email address of the second user. The --local flag changes the configuration file for each repository (.git / config in the root directory of the repository), unlike the --global flag, which modifies ~ / .gitconfig. The default is --local , so you can actually omit it.
Now you have a clone where you are actually the second user. Use another (regular) clone to work as the first user.
* Accurate printing: GitHub Terms of Service allow only one free account per person.