我想重命名我在 GitHub 上的一个存储库,但是当一个大的红色警告说时我很害怕:
- We will not set up any redirects from the old location
- You will need to update your local repositories to point to the new location
- Renaming may take a few minutes to complete
有人有关于如何手动完成#1 和#2 的分步说明吗?或者我必须在本地做什么?
最佳答案
如果您是该项目的唯一人员,这不是什么大问题,因为您只需要做#2。
假设您的用户名是 someuser
,您的项目名为 someproject
。
那么您的项目的 URL 将是1
git@github.com:someuser/someproject.git
如果您重命名您的项目,它将更改 URL 的 someproject
部分,例如
git@github.com:someuser/newprojectname.git
(如果您的 URL 不是这样,请参阅脚注)。
当您执行 push
或 pull
时,您的 Git 工作副本会使用此 URL。
因此在重命名项目后,您必须将新的 URL 告诉工作副本。
您可以分两步完成:
首先,cd
到您的本地 Git 目录,并找出引用该 URL 的远程名称:
$ git remote -v
origin git@github.com:someuser/someproject.git
然后,设置新的URL
$ git remote set-url origin git@github.com:someuser/newprojectname.git
或者在旧版本的 Git 中,您可能需要:
$ git remote rm origin
$ git remote add origin git@github.com:someuser/newprojectname.git
(origin
是最常见的远程名称,但它可能被称为其他名称。)
但是如果有很多人在做你的项目,他们都需要做上面的步骤,也许你甚至不知道如何联系他们告诉他们。这就是 #1 的内容。
进一步阅读:
脚注:
1 您的 URL 的确切格式取决于您使用的协议(protocol),例如
- SSH = git@github.com:someuser/someproject.git
- HTTPS = https://someuser@github.com/someuser/someproject.git
- GIT = git://github.com/someuser/someproject.git
关于git - 如何重命名 GitHub 上的存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5751585/