我可以从现有的存储库中创建新的存储库并重命名它吗? [英] Can I create a new repository out of an existing repository but rename it?

查看:180
本文介绍了我可以从现有的存储库中创建新的存储库并重命名它吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地创建了一个新项目,它是一个包含一些基本代码的模板应用程序(用于即将推出的项目),并将其推送到Github上的远程存储库。并且所有工作都很好。



我试图从模板应用程序中创建新项目(使用它们自己的本地和远程存储库)。例如,假设当前的项目名为TemplateApp。我想建立一个新的项目(基于TemplateApp),但被称为CoffeeMaker(名字应该是本地调用和远程调用)。我怎么做到这一点?



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

    >
  1. 在Github上创建一个新的远程仓库CoffeeMaker。

  2. 在本地TemplateApp中,创建一个新的分支,它将成为CoffeeMaker的主分支。

  3. 将新分支推送至远程CoffeeMaker。

创建新分支时,您可以选择保留还是以前的历史。假设在TemplateApp中最新的 master 创建 new

 #输入本地TemplateApp 
cd TemplateApp

#preserve历史记录
git checkout -b新主记录

#不保存历史
git checkout --orphan new master
git commit -m'init'

#修改文件
git add。
git commit -m'更改为CoffeeMaker'

#将新分支推送到TemplateApp
git push https://github.com/xxx/CoffeeMaker.git -f new :refs / heads / master
#或
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 


I have created a new project locally and it is a template application that has some base code (for upcoming projects), and I pushed it to a remote repository on Github. And all is working fine.

I am trying to create new projects (with their own local and remote repositories) out of that template app. For example, say the current project is called TemplateApp. I want to build a new project (based on TemplateApp) but is called CoffeeMaker (name should both be locally called and remotely). How can I do that?

I tried cloning TemplateApp, then renaming the project locally (and all its files - which is FRUSTRATING) and then do git init and finally push to a new repository. IF this works, I have not succeeded yet as I kept failing in renaming the project locally.

解决方案

  1. Create a new remote repository CoffeeMaker on Github.
  2. In the local TemplateApp, create a new branch which will be the main branch of CoffeeMaker.
  3. Push the new branch to the remote CoffeeMaker.

When creating the new branch, you could choose to preserve the previous history or not. Suppose to create new from the latest master in TemplateApp:

#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

Now the new repository is created with a master branch. You and others can now clone and work:

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

这篇关于我可以从现有的存储库中创建新的存储库并重命名它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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