Git mv重命名存储库中的文件或目录。如何重命名Git存储库本身?


当前回答

这是一个非常简单的解决方案,尽管有些人可能会认为它“不优雅”或“黑客”,它掩盖了我的git不专业。

Verify that your local repo has everything committed and pushed (to remote origin). Go to the website of the remote host (for example, https://github.com/User/project-original-name). Follow the host's instructions to rename the repo (will differ from host to host, but usually Settings is a good starting point). (For the purposes of this guide, suppose you renamed your repo to "project-new-name".) Locally remove your whole repo (e.g., rm -r project-original-name). Do a "fresh checkout": git clone https://github.com/User/project-new-name

注意:如果回购的另一个用户不遵循这些说明,只是在未来进行拉取,我不知道这会产生什么影响。

其他回答

在浏览器上打开git存储库,找到“设置”,你可以看到重命名按钮。

输入新的“存储库名称”并点击“重命名”按钮。

@Parison

Server Side: mv oldName.git newName.git
Client Side: ./.git/config change [remote "origin"] | url to newName.git

在Windows 10上,通过命令行,这个方法很管用:

git checkout <oldname>
git branch -m <newname>

从如何重命名本地和远程Git分支

这是一个本地存储库(不在任何远程设备上)。

对于重命名Git存储库的含义有多种可能的解释:显示的名称、存储库目录或远程存储库名称。每一种都需要不同的重命名步骤。

显示的名字

重命名显示的名称(例如gitweb所显示的名称):

编辑.git/description以包含存储库的名称。 保存文件。

存储库目录

Git不会引用包含存储库的目录的名称,就像Git克隆主子目录所使用的那样,所以我们可以简单地重命名它:

打开命令提示符(或文件管理器窗口)。 更改到包含存储库目录的目录(即,不要进入存储库目录本身)。 重命名目录(例如,从命令行使用mv或从GUI使用F2热键)。

远程存储库

重命名远程存储库如下所示:

转到远程主机(例如https://github.com/User/project)。 按照主机的指示重命名项目(将因主机而异,但通常设置是一个很好的起点)。 转到本地存储库目录(即,打开命令提示符并更改到存储库目录)。 确定新的URL(例如,git@github.com:User/project-new.git) 使用Git设置新的URL: git remote set-url origin git@github.com:User/project-new.git

这是一个非常简单的解决方案,尽管有些人可能会认为它“不优雅”或“黑客”,它掩盖了我的git不专业。

Verify that your local repo has everything committed and pushed (to remote origin). Go to the website of the remote host (for example, https://github.com/User/project-original-name). Follow the host's instructions to rename the repo (will differ from host to host, but usually Settings is a good starting point). (For the purposes of this guide, suppose you renamed your repo to "project-new-name".) Locally remove your whole repo (e.g., rm -r project-original-name). Do a "fresh checkout": git clone https://github.com/User/project-new-name

注意:如果回购的另一个用户不遵循这些说明,只是在未来进行拉取,我不知道这会产生什么影响。