简体   繁体   English

如何合并两个 GitHub 帐户

[英]How to merge two GitHub accounts

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.我有两个 GitHub 帐户,其中一个是很久以前在我的工作中创建的,其用户名是指我工作的公司。

I have another account which is my personal GitHub account that I can't stop using.我有另一个帐户,这是我无法停止使用的个人 GitHub 帐户。

Could I merge the two accounts so I can work in only one of these?我可以合并这两个帐户以便我只能在其中一个帐户中工作吗?

Merging 2 accounts is not possible at github, you can transfer ownership to your personal account.在 github 上无法合并 2 个帐户,您可以将所有权转移到您的个人帐户。

goto  >> Setting >>Transfer ownership 

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

Responding with updated answer here (relevant in 2019).在此处回复更新的答案(与 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 .幸运的是,这是一个相对较快的过程,可以1) 转移回购所有权2) 管理(添加/删除/更改)帐户电子邮件地址,以及3) 保留/转移大多数提交历史记录到个人资料的贡献图

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填写必填字段,输入仓库名称进行确认并输入新所有者的 GH 用户名
  • New owner receives an email with an auth token that expires after 24 hours.新所有者收到一封电子邮件,其中包含 24 小时后过期的身份验证令牌。 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.帐户之间的回购转移包括所有问题、拉取请求、分叉、星号,以及为 git 和 http 设置的自动重定向。 Though you should update your remote's origin URL once the transfer is complete: git remote set-url origin new_url尽管您应该在传输完成后更新遥控器的原始 URL: 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. Git 提交历史、SAML 和其他项目与您在 GitHub 和远程本地设置中存档的电子邮件相关联。 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从 GH 仪表板 > 单击您的个人资料照片下拉菜单 > 设置页面
  • 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您应该登陆您的 GitHub 仪表板,看到电子邮件验证确认横幅

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.之前关于大多数历史转移的说明是指 PR 和属于历史“灰色区域”的问题,并且在合并帐户时不会转移。

After you've added email to GH user account + verified it, most commit history will transfer.在您将电子邮件添加到 GH 用户帐户并对其进行验证后,大多数提交历史将转移。 Allow GitHub a bit of time to propagate the history and contributions between accounts.给 GitHub 一点时间在帐户之间传播历史和贡献。

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 .”这些“ ......一旦帐户被删除,将改为归因于我们的“幽灵”用户,尽管问题/PR 本身不会受到影响。” (from GH Support). (来自 GH 支持)。 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 用户帐户

GitHub does recommend using one user account for personal and professional (work) repositories ( source ), definitely consider doing so! GitHub 确实建议将一个用户帐户用于个人和专业(工作)存储库( ),请务必考虑这样做!

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 .管理多个用户帐户可能很麻烦,尽管有一些方法可以简化多个帐户的工作流程,但是,如果此响应不适合您并且您希望保持多个帐户不变,请参阅如何管理多个 GH使用 SSH 密钥在一台机器上的帐户

While Github outlines a limited " Merging multiple user accounts " process, which is also mentioned in previous answers, it is not a complete solution.虽然 Github 概述了一个有限的“ 合并多个用户帐户”过程,这在之前的答案中也有提到,但它并不是一个完整的解决方案。 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. GitHub 会将来自已删除用户的评论(这将是您按照 GitHub 的帐户合并建议删除的帐户)显示为“幽灵”用户的评论 - 而不会将它们归因于幸存的帐户。 See some more details here:在此处查看更多详细信息:

https://help.github.com/articles/deleting-your-user-account/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.因此,实际上截至 2016 年 11 月,没有通用的方法可以将一个帐户的所有捐款完全合并到另一个帐户。

GitHub has a convenient command-line tool: hub found at https://hub.github.com GitHub 有一个方便的命令行工具: hub位于https://hub.github.com

I've written an example to move all repos from all your organisations to my_new_organisation_name :我编写了一个示例,将所有存储库从您的所有组织移动到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:对于用户而不是组织,将my_new_organisation_name设置为替换用户名,删除外部循环,并将repos=行替换为:

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

EDIT: Found a GUI if you prefer https://stackoverflow.com/a/54549899编辑:如果您喜欢https://stackoverflow.com/a/54549899,请找到一个GUI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM