git 如何重命名 GitHub 上的存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5751585/
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 do I rename a repository on GitHub?
提问by rabbid
I wanted to rename one of my repositories on GitHub, but I got scared when a big red warning said:
我想重命名我在 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
- 我们不会从旧位置设置任何重定向
- 您需要更新本地存储库以指向新位置
- 重命名可能需要几分钟才能完成
Does anyone have step-by-step instructions on how to accomplish #1 and #2 manually? Or what do I have to do locally?
有没有人有关于如何手动完成 #1 和 #2 的分步说明?或者我在当地需要做什么?
回答by Mikel
If you are the only person working on the project, it's not a big problem, because you only have to do #2.
如果您是唯一从事该项目的人,这不是什么大问题,因为您只需要做 #2。
Let's say your username is someuser
and your project is called someproject
.
假设您的用户名是someuser
,您的项目名为someproject
。
Then your project's URL will be1
那么你的项目的 URL 将是1
[email protected]:someuser/someproject.git
If you rename your project, it will change the someproject
part of the URL, e.g.
如果你重命名你的项目,它会改变someproject
URL的一部分,例如
[email protected]:someuser/newprojectname.git
(see footnote if your URL does not look like this).
(如果您的 URL 不是这样,请参阅脚注)。
Your working copy of Git uses this URL when you do a push
or pull
.
当您执行push
或时,您的 Git 工作副本使用此 URL pull
。
So after you rename your project, you will have to tell your working copy the new URL.
所以在你重命名你的项目后,你必须告诉你的工作副本新的 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:
首先,cd
到您本地的 Git 目录,并找出引用该 URL 的远程名称:
$ git remote -v
origin [email protected]:someuser/someproject.git
Then, set the new URL
然后,设置新的 URL
$ git remote set-url origin [email protected]:someuser/newprojectname.git
Or in older versions of Git, you might need:
或者在旧版本的 Git 中,您可能需要:
$ git remote rm origin
$ git remote add origin [email protected]:someuser/newprojectname.git
(origin
is the most common remote name, but it might be called something else.)
(origin
是最常见的远程名称,但也可以称为其他名称。)
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.
但是如果有很多人在做你的项目,他们都需要做上面的步骤,也许你甚至不知道如何联系他们告诉他们。这就是#1 的内容。
Further reading:
进一步阅读:
Footnotes:
脚注:
1 The exact format of your URL depends on which protocol you are using, e.g.
1 您的 URL 的确切格式取决于您使用的协议,例如
- SSH = [email protected]:someuser/someproject.git
- HTTPS = https://[email protected]/someuser/someproject.git
- GIT = git://github.com/someuser/someproject.git
- SSH = [email protected]:someuser/someproject.git
- HTTPS = https://[email protected]/someuser/someproject.git
- GIT = git://github.com/someuser/someproject.git
回答by VonC
Note that since May 2013 ("Repository redirects are here!"), you can rename your GitHub repo without breaking any links:
请注意,自 2013 年 5 月起(“存储库重定向在这里!”),您可以重命名您的 GitHub 存储库而不会破坏任何链接:
We're happy to announce that starting today, we'll automatically redirect all requests for previous repository locations to their new home in these circumstances. There's nothing special you have to do. Just rename away and we'll take care of the rest.
As a special bonus, we'll also be servicing all Git clone, fetch, and push requests from previous repository locations.
我们很高兴地宣布,从今天开始,在这种情况下,我们将自动将以前存储库位置的所有请求重定向到他们的新家。你没有什么特别需要做的。只需重命名,剩下的交给我们。
作为一项特别的奖励,我们还将为来自先前存储库位置的所有 Git 克隆、获取和推送请求提供服务。
That means you don't even have to git remote set-url
(change the url of your remote GitHub repo) on your local cloned repo!
Although Gabrielnotes in the commentsthat the official GitHub help pagestrongly recommends that you do so:
这意味着您甚至不必git remote set-url
(更改远程 GitHub 存储库的 url)在本地克隆存储库上!
虽然加布里埃尔指出在评论是,官方的GitHub帮助页面强烈建议你这样做:
to reduce confusion, we strongly recommend updating any existing local clones to point to the new repository URL. You can do this by using git remote on the command line:
为了减少混淆,我们强烈建议更新任何现有的本地克隆以指向新的存储库 URL。您可以通过在命令行上使用 git remote 来执行此操作:
git remote set-url origin new_url
Beware though:
不过要注意:
GitHub Pagessites are not automatically redirected when their repositories are renamed at this time.
Renaming a Pages repositorywill continue to break any existing links to content hosted on thegithub.io
domain or custom domains.
GitHub Pages站点在此时重命名其存储库时不会自动重定向。
重命名页面存储库将继续破坏指向github.io
域或自定义域上托管的内容的任何现有链接。
Plus, the user still owns the namespace: if he/she creates a newrepo using the old name of the renamed repo, that redirection (for said renamed repo) will stop working.
另外,用户仍然拥有命名空间:如果他/她使用重命名的存储库的旧名称创建一个新的存储库,该重定向(对于所述重命名的存储库)将停止工作。
回答by pollux1er
I rename my own just by simply :
我只是简单地重命名我自己的:
- going to github.com on my repository
- Open Settings Tab
- The first setting you can see is the "Repository Name"
- Change the actual one and put the new name you want to give to your repository
- Click on Rename
- 在我的存储库上访问 github.com
- 打开设置选项卡
- 您可以看到的第一个设置是“存储库名称”
- 更改实际名称并将新名称放入您的存储库
- 点击重命名
After this step, GitHub will make sure that, your online repository matches your local folder name. At this step your problem is solved, unless you also want to rename your local folder. Then do it manually and just use the Github client for windows to refind again your repository into your hard drive, and Github will match it again. That's all! Very simple.
在此步骤之后,GitHub 将确保您的在线存储库与您的本地文件夹名称匹配。在此步骤中,您的问题已解决,除非您还想重命名本地文件夹。然后手动执行,只需使用 Windows 的 Github 客户端将您的存储库再次重新查找到您的硬盘驱动器中,Github 将再次匹配它。就这样!很简单。
回答by Rajnish Rajput
The simplest way I found
我发现的最简单的方法
Go to your repo link for example:-
https://github.com/someuser/someRepo.git
Click on setting tab.
转到您的回购链接,例如:-
https://github.com/someuser/someRepo.git
单击设置选项卡。
the first thing you can see is your repo name, you can edit that.
您可以看到的第一件事是您的回购名称,您可以对其进行编辑。
Note:- If you have cloned repo on local so, change its folder name manually, that's all.
注意:- 如果您在本地克隆了 repo,请手动更改其文件夹名称,仅此而已。
回答by cesards
I see a lot of positive feedback to responses I don't find accurate/complete at all.
我看到很多对我根本不准确/不完整的回复的积极反馈。
There are two things to have in mind:
有两点需要注意:
- Remote repository
- Local copy of the repository
- 远程仓库
- 存储库的本地副本
If you haven't cloned your repo in your machine yet, you just need to rename the Github repository and then proceed to clone the repo so you can have a local copy. In order to rename the Github repo, you just need to:
如果你还没有在你的机器上克隆你的 repo,你只需要重命名 Github 存储库,然后继续克隆 repo,这样你就可以有一个本地副本。为了重命名 Github 存储库,您只需要:
- Go to the repository site (i.e https://github.com/userX/repositoryZ).
- In the navigation bar, you will see a tab named "Settings". Click on it.
- Just edit the current repository name with the desired one and press "Rename".
- Clone the repository as usual (i.e git clone https://github.com/userX/repositoryU).
- 转到存储库站点(即https://github.com/userX/repositoryZ)。
- 在导航栏中,您将看到一个名为“设置”的选项卡。点击它。
- 只需使用所需的名称编辑当前存储库名称,然后按“重命名”。
- 像往常一样克隆存储库(即 git clone https://github.com/userX/repositoryU)。
If you already have a local copy of the project, apart from following the steps above, you need to make sure your local repository (root folder) is renamed properly and it's pointing to the right remote url :) link. In order to achieve that, do the following:
如果您已经拥有该项目的本地副本,除了执行上述步骤之外,您还需要确保您的本地存储库(根文件夹)已正确重命名,并且它指向正确的远程 url :) 链接。为了实现这一点,请执行以下操作:
- You might want to use the new given name for your repo. To do so, rename the local folder either by using the OS GUI(Finder, Windows Explorer, etc.) or console:
- 您可能希望为您的存储库使用新的给定名称。为此,请使用 OS GUI(Finder、Windows Explorer 等)或控制台重命名本地文件夹:
mv -R current-repo-name new-repo-name
mv -R current-repo-name new-repo-name
- Change the remote url. From the root of the folder, use the following:
- 更改远程 URL。从文件夹的根目录,使用以下命令:
$ git remote set-url origin https://github.com/userX/repositoryU
$ git remote set-url origin https://github.com/userX/repositoryU
or
或者
$ git remote set-url origin [email protected]:userX/repositoryU.git
$ git remote set-url origin [email protected]:userX/repositoryU.git
The second step is not mandatory, though. Github announced a while ago that they would redirect all requests from previous repository urls to the assigned ones. That means you don't need to use $ git remote set-url ...
, but they still encourage you to do so to avoid confusion.
不过,第二步不是强制性的。Github 不久前宣布,他们会将所有请求从以前的存储库 url重定向到指定的。这意味着您不需要使用$ git remote set-url ...
,但他们仍然鼓励您这样做以避免混淆。
Hope it helped. If you have any questions or the post is not clear enough, let me know.
希望它有所帮助。如果您有任何问题或帖子不够清楚,请告诉我。
回答by JonnyJD
This answer is now obsolete!GitHub will forward to new locations now. See this answerfor details.
这个答案现在已经过时了!GitHub 现在将转发到新位置。有关详细信息,请参阅此答案。
The reason this warning is there is because #1 can'tbe made manually.
出现此警告的原因是无法手动生成#1 。
If you are the only person working on and linking to the repository, then you are fine with changing the remote in your local repo and in your webpages.
如果您是唯一一个处理和链接到存储库的人,那么您可以更改本地存储库和网页中的远程。
However, the reason to have a public repository on github in the first place is that you can have others cloning your repository and linking to your github project page.
但是,首先在 github 上拥有公共存储库的原因是您可以让其他人克隆您的存储库并链接到您的 github 项目页面。
The old url github.com/<username>/<repository>
is owned by github.
When they don't setup any redirects to the new url, nobody can.
So things will break for everybody except the persons you are telling.
旧 urlgithub.com/<username>/<repository>
归 github 所有。当他们不设置任何重定向到新 url 时,没有人可以。因此,除了你告诉的人之外,每个人的事情都会破裂。
How big of a problem that is, is up to you though. If you have an official project page on a different server, then the github url might not be much of a problem. If you advertised your project with the github url in mailing lists and directories, then you probably should not change the repo name.
问题有多大,取决于你。如果你在不同的服务器上有一个官方的项目页面,那么 github url 可能不是什么大问题。如果您在邮件列表和目录中使用 github url 宣传您的项目,那么您可能不应该更改 repo 名称。
An alternative to changing the repo name is to create a new repository and leave notes in the old one (also as commits in the repo) about how to reach your new repo.
更改存储库名称的另一种方法是创建一个新存储库,并在旧存储库中留下关于如何到达新存储库的注释(也作为存储库中的提交)。
If you wan't your new repo to be listed as a fork of your old repo you need to create a new github account. You can add your other account as a collaborator for both repositories.
如果您不想将新存储库列为旧存储库的分支,则需要创建一个新的 github 帐户。您可以将其他帐户添加为两个存储库的协作者。
回答by Neil Best
It is worth noting that if you fork a GitHub project and then rename the newly spawned copy, the new name appears in the members network graph of the parent project. The complementary relationship is preserved as well. This should address any reservations associated with the first point in the original question related to redirects, i.e. you can still get here from there, so to speak. I, too, was hesitant because of the irrevocability implied by the warning, so hopefully this will save others that delay.
值得注意的是,如果你 fork 一个 GitHub 项目,然后重命名新生成的副本,新名称会出现在父项目的成员网络图中。互补关系也得以保留。这应该解决与重定向相关的原始问题中第一点相关的任何保留,即您仍然可以从那里到达这里,可以这么说。我也因为警告所暗示的不可撤销性而犹豫不决,所以希望这可以避免其他人的延误。
回答by reshma
- Navigate to your repository path.
- Click on settingbutton which is there in right panne.
- Replace old repository name to new name.
- Click on Renamebutton
- 导航到您的存储库路径。
- 单击右侧窗格中的设置按钮。
- 将旧存储库名称替换为新名称。
- 点击重命名按钮
回答by Faiyaz Alam
This solution is for those users who use GitHub desktop.
此解决方案适用于使用 GitHub 桌面的用户。
Rename your repository from setting on GitHub.com
Now from your desktop click on sync.
从 GitHub.com 上的设置重命名您的存储库
现在从您的桌面单击同步。
Done.
完毕。
回答by tamer kamal
open this url (https://github.com/) from your browser
Go to repositories at the Right end of the page
Open the link of repository that you want to rename
click Settings (you will find in the Navigation bar)
At the top you will find a box Called (Repository name) where you write the new name
Press Rename
从浏览器打开这个 url ( https://github.com/)
转到页面右端的存储库
打开要重命名的存储库链接
单击设置(您会在导航栏中找到)
在顶部,您会找到一个名为(存储库名称)的框,您可以在其中写入新名称
按重命名