Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...