1

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.

Sandra K
  • 1,209
  • 1
  • 10
  • 21
  • 1
    If you want an entirely new project based on the content of the template application but not its git history, it's best to remove the `git` directory and then perform whatever rename operation you want. – merlin2011 Feb 24 '18 at 01:59

2 Answers2

1
  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
Nayagam
  • 1,767
  • 18
  • 12
ElpieKay
  • 27,194
  • 6
  • 32
  • 53
1

On GitHub, since June 2019, you don't have to clone "TemplateApp" and rename it.

You now can define a repository template, and call the /generate endpoint (or click on the button "Use this template").
All you will need to do is name your project and clone your new repository to get started, based on that one "TemplateApp" repository template!

See "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.

https://github.blog/wp-content/uploads/2019/06/repository-template.gif

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

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250