Mark Bolusmjak
Mark Bolusmjak

Reputation: 24399

What is the proper git workflow for basing a project off a 'seed' repo?

As an example: suppose you have a personal project like Angular Seed (which is a starting point for an Angular project https://github.com/angular/angular-seed).

Now you want to use that as a starting point for a project (say an online photo album).

You shouldn't just create a branch because you're not making a variation of the seed project. But github won't let you fork it if it's your own repo.

So what is the workflow to create a clone that can still pull in changes form the original seed project? I thought that was a fork.

Upvotes: 19

Views: 5256

Answers (5)

Alex
Alex

Reputation: 2359

I found mirroring the boilerplate according to this article the only way to work for me:

Clone boilerplate and create new project:

git clone --mirror https://github.com/mxstbr/react-boilerplate.git
cd react-boilerplate.git
git remote set-url --push origin https://github.com/gitUser/newProject

Update the new project with changes from the boilerplate:

cd react-boilerplate.git
git fetch -p origin
git push --mirror

Upvotes: 1

Konstantin Tarkus
Konstantin Tarkus

Reputation: 38378

Option 1: clone / fetch / merge

Clone the master branch of the seed project of your choice, for example:

$ git clone -o react-starter-kit -b master --single-branch \
      https://github.com/kriasoft/react-starter-kit.git MyApp
$ cd MyApp

Down the road, you can pull and merge updates from the seed project back into your local repo by running:

$ git checkout master
$ git fetch react-starter-kit
$ git merge react-starter-kit/master
$ npm install

Option 2: clone / pull / diff

Clone the seed project and remove its version history:

$ git clone https://github.com/kriasoft/react-starter-kit --depth=1
$ git clone https://github.com/kriasoft/react-starter-kit MyApp --depth=1
$ cd MyApp
$ rm -rf .git

Then, whenever you need to pull the latest updates from the seed project back into your local repo, you can navigate to the original seed project, pull the updates (git pull), then compare that folder with your project's folder by using some good Diff tool (e.g. Beyond Compare) that allows you to save and customize folder comparison sessions.

Upvotes: 3

Kyle Boon
Kyle Boon

Reputation: 5231

I think the right answer here is to use something like Yeoman Generators. (http://yeoman.io/) You want to use the git repo with your seed project as a generator. It wouldn't allow you to continually pull in changes from the seed project though.

The solution of using two remotes works, but eventually the projects will diverge enough that will make keeping those projects in synch very difficult.

Upvotes: 5

VonC
VonC

Reputation: 1324218

What you could do is:

  • initialize a new repo
  • reference your angular repo as a submodule of that new repo
  • push that new repo in your GitHub space.

That way, your new project has:

  • a subfolder representing your seed project (which you don't modify)
  • all your data specific to your project.

My issue with that is that a seed project isn't a library. It doesn't live in a subdirectory of a project. It IS the project when you start, and you build from there.

Then a simple clone that you push back to your new repo is enough.
But that won't keep any "fork" relationship between your two GitHub repos.
You will have to pull one and push to the other through a local clone.

Upvotes: 4

Mark Bolusmjak
Mark Bolusmjak

Reputation: 24399

I just found this answer https://stackoverflow.com/a/4096529/131227 as well as a comment (git workflow - using one repo as the basis for another) which together lead me to a solution I like.

git clone -o boilerplate ssh://[email protected]/user/proj.git new_proj
The -o boilerplate renames the origin to boilerplate which can still be used to pull changes from.

Create your new empty github new_proj repo. Then
git remote add origin ssh://[email protected]/user/new_proj.git

Upvotes: 28

Related Questions