DEV Community

Cover image for Merge github accounts (work + personal)
Benj Hingston
Benj Hingston

Posted on

Merge github accounts (work + personal)

This article was originally published on 2019-07-05


First let us start with why you would want to do this. With Github being one of the top source-code-hosting platforms and growing features on user stats around contributions, Github makes sense to be a developer’s portfolio. Also Github recommends using only one account.

We recommend using only one user account to manage both personal and professional repositories. ~ Github1

If that hasn’t convinced you; think about yourself 1 year, 5 years, and 10 years from now. What does your current career look like? You may still be at your current company (and why shouldn’t you - it’s an awesome place to be!) or your career has taken you elsewhere. If you see yourself no longer with your company wouldn’t it be nice to have all you contributions you have made over your career*? You might not be able to show code from private repos but you should be able to showcase your contributions to your previous work.

*Disclaimer: commit history and contribution stats follow the email (not the GitHub account) so as you may add/remove emails from one account or another the actual commits follow the email.

How might we do this you might ask; do not worry, you have come to the right place.

My first approach was transferring all the repos I created and forked on my Company GitHub account, but after reading the fine print of the blog and Github docs I found out only commits made to those transferred repositories would be transferred. With this I switched my game plan. I am going to walk through merging personal account to my work account. The down side I could lose PRs and Issues created with my personal account but this was minimal to the contributions I made to my company.

After reading some stale Stack Overflow questions and other forums that all concluded this was not possible I finally found one Stack Overflow comment that referenced a blog published earlier this year (link to blog at the end). When Github introduced the ability to have multiple emails tied to one GitHub account this transfer of commit history and contribution stats was now possible!

1. How to Transfer Repository Owner on GitHub2

  1. From Repo → Settings page → Options → scroll to the bottom, looking for red-colored “Transfer” button within the “Danger Zone”
  2. Fill out the required fields, typing the name of the repository to confirm and entering the new owner’s GitHub username
  3. New owner receives an email with an auth token that expires after 24 hours. Be sure to check that email for the account you’re transferring to and follow the link to fully complete any repo transfers.

2. Account Email Management on GitHub + Git Commit History2

Git commit history, SAML, and other items are tied to the email(s) you have on-file within GitHub and in your remote, local setup. When consolidating multiple GitHub accounts into one, this is an essential step to cover to ensure you keep any commit history + have it added to contribution graph on user profile. ~ Scott Mathson

Pull requests and issues fall under this “certain criteria” grey area. Most commit history will transfer once the email address that authored those commits have been added to your account. With the exception/caveat of losing pull requests and issues commit histories, more on this below. ~ Scott Mathson

3. How to add/verify one (or many) email addresses to your GitHub account2

  1. From GitHub dashboard → Click your profile photo dropdown → Settings
  2. Click on Emails in the left sidebar → Add email address field → Add new email
  3. Check your inbox for the email address you’ve just added and click the link included**. You should land on your GitHub dashboard, seeing an email verification confirmation banner.

**The above 3 sections are covered in more detail in the referenced blog. The following is an extension so you can use your new email to start tracking your contributions for the rest of your career.

If you only have one email on the account you are transferring from you may want to add a second email so you can leave that GitHub account open while you move emails around (alternative is to permanently delete the GitHub account so the email is free to be transferred - this alternative you would lose all your data on the GitHub account you deleted).

*Note you need to be signed into your destination GitHub account when you open the link (I had to copy the link in the email that I opened in my personal Google account and paste it into the window where I was signed into with my Company Google account.

PRs and Issues won’t transfer but you can assign your work account to any open PRs.

With the new email verified you should see your commits follow your email:
Image description
Image description

4. How to track contributions going forward with your personal email

4.a Local Signed Commits

Now we need to update the email used to sign git commits local and web based. For local commits you can achieve this by running:

  1. Open Terminal.
  2. Set an email address in Git. You can use your GitHub-provided no-reply email address or any email address associated with GitHub account.

    $ git config --global user.email "[email@example.com](mailto:email@example.com)"
    
  3. Confirm that you have set the email address correctly in Git:

    $ git config --global user.email
    
    [email@example.com](mailto:email@example.com)
    
  4. Add the email address to your GitHub account by setting your commit email address, so that your commits are attributed to you and appear in your contributions graph.

4.b Web based Signed Commits

For web base*** you need to update your primary email.4

  1. From GitHub dashboard → Click your profile photo dropdown → Settings
  2. Click on Emails in the left sidebar → Primary email address selector → Select email

***Think of actions done in the Github platform like PR merges, commit suggestions, etc.

Done! Now go and make your first commit with your personal email!!

References

  1. GitHub Docs Merging Users
  2. Blog Reference
  3. GitHub Docs Transferring Repos
  4. GitHub Docs Setting Commit Email


Original Comments

2019-07-10 03:38 author said:

I forgot to highlight the relationships between the GitHub account, username (@ tag), and emails and what is tracked and transferred with each. A GitHub account has one user name, and one or many emails. Usernames have to be unique (2 accounts cannot have the same username) although usernames can change (freeing up the previous to be used by another account). An email can only be associated with one GitHub account at a time but can be removed and added to any GitHub account.

GitHub accounts own repos and Pull Requests and Issues follow the GitHub account (ghost account if deleted). It is also GitHub accounts that can be asked to be members of enterprise GitHub accounts (my current work GitHub account is a member of my company's GitHub account and the enterprise account owns the company's repos).

@ mentions follow the username and can be changed (although existing mentions won't change).

Commits follow the email.


2019-10-07 23:00 anonymous user 1 said:

Gave it a shot and the steps worked for me! Thanks


2020-06-25 22:24 Joel Kesler said:

Thanks! Worked for me too!


2021-06-18 22:27 Joel Kesler said:

Someone asked me what I did, so I updated the instructions for him. I will include the instructions here too to help others:

This is how I did it:

  • And your team's github team
  • Then in your Personal Github Account, add your work email as a secondary email in Settings > Emails

If Github gives you an error when adding in your work email address, then do the following:

  • in your Company's Github Account, add a company email address with alias, like jkesler+github@mycompany.com
  • When the new email alias address is verified, set it to primary
  • remove your old work email address from Company Github Account
  • Then, in your Personal Github Account add your main work email address
  • Set your main work email address as your primary email address in you Personal Github Account

To add your email to your local git:

  • open your local ~/..gitconfig in your favorite editor
  • change your email address to your personal address
  • you may need to regenerate a signing key if you have one

Once everything is working well, you can delete your work Github Account. I waited two weeks or so just to make sure things were working well


2021-06-21 17:44 anonymous user 2 said:

thx for this!

note some emails got rewritten to markdown links in some code blocks, should be just the email address not the [email](mailto:email) thing

Top comments (0)