git 如何安全地更改github帐户名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10889436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to safely change github account name?
提问by mikhail-t
I would like to change my github account name, I found an option in GitHubaccount settings.
我想更改我的 github 帐户名称,我在GitHub帐户设置中找到了一个选项。
However, I am concerned about consequences and would like to know what is the best strategy of name change, considering that I have some projects of my own tied to this account.
但是,考虑到我自己的一些项目与此帐户相关联,我担心后果并想知道更改名称的最佳策略是什么。
So far, I came up with this plan:
到目前为止,我想出了这个计划:
- Change account name in GitHub settings
- For each project's local folder in '.git / config' file update remote "origin"url to the new one
- 在 GitHub 设置中更改帐户名称
- 对于'.git / config'文件中每个项目的本地文件夹,将远程“origin”url更新为新的
Will this work? Should there be any further steps on a computer which holds project sources? What will be the effect of name change on those who cloned or forked my projects on GitHub?
这会奏效吗?在保存项目源的计算机上是否应该有任何进一步的步骤?更名对在 GitHub 上克隆或分叉我的项目的人会有什么影响?
Thank you!
谢谢!
采纳答案by Fatih Arslan
1.) You have to change all your projects remote addresses. You can see them via:
1.) 您必须更改所有项目的远程地址。您可以通过以下方式查看它们:
git remote -v
After that remove the old remote addres:
之后删除旧的远程地址:
git remote rm [email protected]:old_account/foo.git
finally add your new remote address:
最后添加您的新远程地址:
git remote add origin [email protected]:new_account/foo.git
2.) All your cloned repos will break. There is no URL-redirect or anything similar. You can change your local cloned repos, but others have to point to the new repo addres(like in Step 1)
2.) 你所有克隆的 repos 都会损坏。没有 URL 重定向或类似的东西。您可以更改本地克隆的存储库,但其他人必须指向新的存储库地址(如步骤 1 中所示)
Note: Github forked repos works without any problem.
注意:Github 分叉存储库可以正常工作。
回答by Nick McCurdy
GitHub has recently changed their username rename system, and now sets up redirects for you.
GitHub 最近更改了他们的用户名重命名系统,现在为您设置重定向。
From What happens when I change my username?on GitHub Help:
从当我更改用户名时会发生什么?在 GitHub 帮助上:
On the GitHub side, everything will behave as if your new username had always been your name. All of your repositories will now belong to that new name and the old username will essentially no longer exist. This can take a few minutes to complete after you initiate the change.
Links to your previous profile page, such as https://github.com/previoususername, return a 404 error. We cannot set up a redirect from the old username to the new one for references like @mentions.
However, redirects are setup for all your repositories. Both web and git access to the old location continue to function, and redirect toward the new username.
在 GitHub 端,一切都会像你的新用户名一直是你的名字一样。您的所有存储库现在都将属于该新名称,并且旧用户名基本上不再存在。在您启动更改后,这可能需要几分钟才能完成。
指向您之前的个人资料页面的链接,例如 https://github.com/previoususername,会返回 404 错误。对于@mentions 之类的引用,我们无法设置从旧用户名到新用户名的重定向。
但是,您的所有存储库都设置了重定向。对旧位置的 web 和 git 访问继续起作用,并重定向到新用户名。
回答by richo
I left a script in my ~/bin called git-reremote with the following content:
我在 ~/bin 中留下了一个名为 git-reremote 的脚本,其中包含以下内容:
#!/bin/sh
old=richoH
new=richo
git remote -v | grep $old | while read name url type; do
newurl=`echo $url | sed -e "s/$old/$new/"`
git remote set-url $name $newurl
done
It's a bit of a hack but it works nicely enough, just cd into the git repo and call git reremote
(after making sure it's in your $PATH
and also that you've fixed the old and new variables.
这是一个小技巧,但它工作得很好,只需 cd 进入 git repo 并调用git reremote
(在确保它在你的里面$PATH
并且你已经修复了旧的和新的变量之后。