How to merge two GitHub accounts

GitGithub

Git Problem Overview


I have two GitHub accounts, one of this was created a long time ago at my work and has an username that refers to the company where I work.

I have another account which is my personal GitHub account that I can't stop using.

Could I merge the two accounts so I can work in only one of these?

Git Solutions


Solution 1 - Git

Merging 2 accounts is not possible at github, you can transfer ownership to your personal account.

goto  >> Setting >>Transfer ownership 

For more details : https://help.github.com/articles/merging-multiple-user-accounts/

Solution 2 - Git

Responding with updated answer here (relevant in 2019).

Luckily this is a relatively quick process to 1) transfer repo ownership, 2) manage (add/remove/change) account email addresses, and 3) keep/transfer most commit history to the profile’s contribution graph.

Transferring repository ownership only requires a few steps.

  • From Repo > Settings page > Options > scroll to the bottom, looking for red-colored “Transfer” button within the “Danger Zone”
  • Fill out the required fields, typing the name of the repository to confirm and entering the new owner’s GH username
  • 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

Repo transfers between accounts includes all issues, pull requests, forks, stars, alongside automatic redirects being setup for git and http. Though you should update your remote’s origin URL once the transfer is complete: git remote set-url origin new_url

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. Keeping/transferring commit history to contribution graph comes when you add original, authoring email/verify it on user account you're consolidating/merging into.

  • From GH dashboard > Click your profile photo dropdown > Settings page
  • Click on Emails in the left sidebar > Add email address field > Add new email
  • 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

Previous note about most history transferring is referring to PRs and issues which fall under this "grey area" of history and will not transfer when combining accounts.

After you've added email to GH user account + verified it, most commit history will transfer. Allow GitHub a bit of time to propagate the history and contributions between accounts.

You will lose commits tied to original pull requests and issues histories tied to account you're removing. These “...would instead be attributed to our “Ghost” user once the account is deleted, though the issues/PRs themselves would otherwise be unaffected.” (from GH Support). If you're looking to read more, I wrote up a quick blog article for this with steps and visuals on transferring repo ownership, adding emails, and more - how to merge/combine two (or many) GitHub user accounts.

GitHub does recommend using one user account for personal and professional (work) repositories (source), definitely consider doing so!

Managing multiple user accounts can be cumbersome, though there are ways to simplify workflow of multiple accounts, though, so in the case this response wasn't for you and you want to keep your many accounts as-is, see how to manage multiple GH accounts on one machine with SSH keys.

Solution 3 - Git

While Github outlines a limited "Merging multiple user accounts" process, which is also mentioned in previous answers, it is not a complete solution. It does not resolve ownership in third party repositories contributions.

GitHub will display comments from a deleted user (which will be the account you got rid of following GitHub's account merge suggestion) as "ghost" user's comments - without attributing them to the surviving account. See some more details here:

https://help.github.com/articles/deleting-your-user-account/

So in reality as of November 2016 there is no general way to fully merge all contributions from one account to another.

Solution 4 - Git

GitHub has a convenient command-line tool: hub found at https://hub.github.com

I've written an example to move all repos from all your organisations to my_new_organisation_name:

#!/usr/bin/env bash

orgs="$(hub api '/user/orgs' | jq -r '.[] | .login')";
repos="$(for org in $orgs; do hub api '/orgs/'"$org"'/repos' | jq -r '.[] | .name';
         done)"

for org in $orgs; do
    for repo in $repos; do
        ( hub api '/repos/'"$org"'/'"$repo"'/transfer'
                  -F 'new_owner'='my_new_organisation_name' | jq . ) &
    done
done

For users rather than organisation, set my_new_organisation_name to the replacement username, remove the outer loop, and replace the repos= line with:

repos="$(hub api /users/SamuelMarks/repos | jq -r '.[] | .name')"

EDIT: Found a GUI if you prefer https://stackoverflow.com/a/54549899

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRodrigo CurbeloView Question on Stackoverflow
Solution 1 - GitMohammad FareedView Answer on Stackoverflow
Solution 2 - GitScott MathsonView Answer on Stackoverflow
Solution 3 - GitVlad DidenkoView Answer on Stackoverflow
Solution 4 - GitSamuel MarksView Answer on Stackoverflow