DEV Community

Prathviraj H
Prathviraj H

Posted on

Using Multiple GitHub Accounts

When I started working with multiple GitHub accounts on the same laptop, I was confused about how authentication actually works. I used to think GitHub checks my email or username when I push code, but I learned that GitHub mainly identifies me using SSH keys.

SSH is a secure way for my computer to prove its identity to GitHub. Instead of typing a username and password every time, my laptop shows a digital identity in the form of a key. This makes pushing and pulling code faster and safer.

I learned that SSH always comes in pairs: a public key and a private key. The public key is shared with GitHub, and the private key stays only on my laptop. GitHub keeps the public key, and when I try to connect, my laptop proves it owns the matching private key. If they match, access is granted.

An important concept I understood is that the private key must never be shared with anyone. Only the public key is meant to be copied and added to GitHub.

I also learned about the SSH agent. The SSH agent is a background helper that remembers which private keys are available on my system. Because of the agent, I do not have to re-enter passphrases every time I use Git. It acts like a key holder that temporarily stores my keys in memory.

Another big learning was about the SSH configuration file. This file allows me to define multiple identities on the same machine. I can give each GitHub account a nickname and map that nickname to a specific private key. This means I can tell my system which key should be used for which account.

Because of this setup, I now understand that Git decides which GitHub account to use based on the repository’s remote address. The remote address contains a host alias, and that alias points to a specific key in the SSH configuration file. So the remote URL indirectly controls which GitHub account is used.

I also learned that commit email and GitHub authentication are two different things. The email written in a commit only affects how the commit appears in history. It does not decide which GitHub account is pushing the code. The actual account is decided only by the SSH key being used.

Another useful concept I understood is that Git configuration exists at two levels: global and local. Global configuration applies to all repositories on my system. Local configuration applies only to one specific project. This allows me to use my own email for my projects and my friend’s email only inside my friend’s repository.

I learned how to check which keys are currently loaded in the SSH agent and how to remove or re-add them. This helped me understand that multiple keys can exist at the same time, and Git will choose the correct one based on configuration and remote URL.

Overall, I now clearly understand that SSH keys control who I authenticate as, remote URLs decide which key is used, and commit email only controls how my name appears in history. This knowledge allows me to safely work with multiple GitHub accounts on the same laptop without conflicts.

Top comments (0)