如何重命名 GitHub 上的存储库? [英] How do I rename a repository on GitHub?

查看:41
本文介绍了如何重命名 GitHub 上的存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重命名我在 GitHub 上的一个存储库,但是当一个大红色警告说时我很害怕:

<块引用>

  1. 我们不会从旧位置设置任何重定向
  2. 您需要更新本地存储库以指向新位置
  3. 重命名可能需要几分钟才能完成

有没有人有关于如何手动完成 #1 和 #2 的分步说明?或者我必须在本地做什么?

解决方案

如果你是唯一一个在项目上工作的人,这不是什么大问题,因为你只需要做 #2.

假设您的用户名是 someuser,您的项目名为 someproject.

那么你的项目的 URL 将是1

git@github.com:someuser/someproject.git

如果你重命名你的项目,它会改变 URL 的 someproject 部分,例如

git@github.com:someuser/newprojectname.git

(如果您的 URL 不是这样,请参阅脚注).

当您执行 pushpull 时,您的 Git 工作副本使用此 URL.

因此,在重命名项目后,您必须将新 URL 告诉您的工作副本.

您可以分两步完成:

首先,cd 到您本地的 Git 目录,并找出远程名称引用该 URL:

$ git remote -v起源 git@github.com:someuser/someproject.git

然后,设置新网址

$ 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 的确切格式取决于您使用的协议,例如

I wanted to rename one of my repositories on GitHub, but I got scared when a big red warning said:

  1. We will not set up any redirects from the old location
  2. You will need to update your local repositories to point to the new location
  3. Renaming may take a few minutes to complete

Does anyone have step-by-step instructions on how to accomplish #1 and #2 manually? Or what do I have to do locally?

解决方案

If you are the only person working on the project, it's not a big problem, because you only have to do #2.

Let's say your username is someuser and your project is called someproject.

Then your project's URL will be1

git@github.com:someuser/someproject.git

If you rename your project, it will change the someproject part of the URL, e.g.

git@github.com:someuser/newprojectname.git

(see footnote if your URL does not look like this).

Your working copy of Git uses this URL when you do a push or pull.

So after you rename your project, you will have to tell your working copy the new URL.

You can do that in two steps:

Firstly, cd to your local Git directory, and find out what remote name(s) refer to that URL:

$ git remote -v
origin  git@github.com:someuser/someproject.git

Then, set the new URL

$ git remote set-url origin git@github.com:someuser/newprojectname.git

Or in older versions of Git, you might need:

$ git remote rm origin
$ git remote add origin git@github.com:someuser/newprojectname.git

(origin is the most common remote name, but it might be called something else.)

But if there are lots of people who are working on your project, they will all need to do the above steps, and maybe you don't even know how to contact them all to tell them. That's what #1 is about.

Further reading:

Footnotes:

1 The exact format of your URL depends on which protocol you are using, e.g.

这篇关于如何重命名 GitHub 上的存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆