What can happen with two Github accounts?
Recently I needed to switch between my two Github accounts while working on personal projects.
My primary Github account (which we'll refer to as my "personal Github") is for anything I work on during my personal web development learning. I created a second Github account that I can use for applying to jobs and other opportunities (we can call her my "work Github").
I committed a project to what I thought was my work Github using the command line before realizing that I had actually made the commits on my personal Github account. The problem? This personal project was incomplete and would reflect poorly on me if a hiring manager saw it. So I had to figure out how to switch between my two Github account when in the CLI on my computer.
So I went in search of a solution, and one in Github's documentation and in articles written by developers and hobbyists.
The command
teeteate:~$ alias git_personal='git config --global user.email {personal@mail} && git config --global user.name {personal_name}'
teeteate:~$ alias git_work='git config --global user.email {work@mail} && git config --global user.name {work_name}'
These two commands allow you to enter your preferred Github account's associated user name and email address in order to switch between the instances that are pushing code from your terminal. Pick either one and edit them between the {} by adding in your personal or work Github account details and removing the {} afterward.
I've been able to easily switch between my two Github accounts this way. I only use two accounts, but you could continue to switch between three or more Github accounts using the commands.
Another quirk
One thing I noticed was that my personal Github account username was still somehow listed as a collaborator for a repository that was only on my work Github account.
To fix this, I blocked my personal Github account username while logged into Github.com with my work Github account, and I blocked my work Github account while logged into Github.com using my personal Github account. This means that each of my accounts will be prevented from pushing my projects to the other account, and there will not be collaborator mixups between the two accounts.
What is this useful?
I use Github a few times a week right now while updating my current projects. Next month I will use it even more for pushing personal and portfolio projects. I loved learning about a way to switch between my two accounts easily from the command line. I hope you can use this tip in your own coding journey!
Let's connect!
In the comments below, share your Github and one fun tip or trick you learned that is helpful for using Github.
Top comments (0)