我可以从现有存储库创建一个新存储库但重命名它吗?

Can I create a new repository out of an existing repository but rename it?

我在本地创建了一个新项目,它是一个具有一些基本代码(用于即将进行的项目)的模板应用程序,我将其推送到 Github 上的远程存储库。一切正常。

我正在尝试使用该模板应用程序创建新项目(具有自己的本地和远程存储库)。例如,假设当前项目名为 TemplateApp。我想构建一个新项目(基于 TemplateApp),但名为 CoffeeMaker(名称应为本地调用和远程调用)。我该怎么做?

我尝试克隆 TemplateApp,然后在本地重命名项目(及其所有文件 - FRUSTRATING),然后执行 git init,最后推送到新的存储库。 IF 这行得通,我还没有成功,因为我在本地重命名项目一直失败。

  1. 在 Github 上创建一个新的远程存储库 CoffeeMaker。
  2. 在本地 TemplateApp 中,新建一个分支作为 CoffeeMaker 的主分支。
  3. 将新分支推送到远程 CoffeeMaker。

创建新分支时,您可以选择是否保留之前的历史记录。假设从 TemplateApp 中最新的 master 创建 new

#enter the local TemplateApp
cd TemplateApp

#preserve the history
git checkout -b new master

#don't preserve the history
git checkout --orphan new master
git commit -m 'init'

#modify the files
git add .
git commit -m 'changes for CoffeeMaker'

#push the new branch to TemplateApp
git push https://github.com/xxx/CoffeeMaker.git -f new:refs/heads/master
#or
git remote add coffee https://github.com/xxx/CoffeeMaker.git
git push coffee -f new:refs/heads/master

现在新的存储库创建了一个 master 分支。您和其他人现在可以克隆和工作:

git clone https://github.com/xxx/CoffeeMaker.git

在 GitHub,自 2019 年 6 月起,您不必克隆“TemplateApp”并重命名它。

您现在可以定义一个 存储库模板 ,并调用 /generate 端点(或单击按钮 "Use this template")。
您需要做的就是根据那个“TemplateApp”存储库模板命名您的项目并克隆您的新存储库以开始使用!

参见“Generate new repositories with repository templates”:

Sharing boilerplate code across codebases is a constant pattern in software development.
Bootstrapping a new project with our favorite tools and directory structures helps programmers go from idea to “Hello world!” more efficiently and with less manual configuration.

Today, we’re excited to introduce repository templates to make boilerplate code management and distribution a first-class citizen on GitHub.

To get started, all you need to do is mark a repository as a template, and you’ll immediately be able to use it to generate new repositories with all of the template repository’s files and folders.

Every template repository gets a new URL endpoint called /generate that allows you to distribute your template more efficiently