Take the tour ×

I'm wondering if this is going to work...

Say i have a project template something like that:

+ resources/
  + images/

I want to use this project as a template for other projects, so they would be essentially "cloned" from the template but maintained as a separate repository.

However, I would still like to be able to pull updates from the template whenever they occur (but don't care to push to it).

Submodules or subtree merge don't seem to fit here because it is not cloned into a sub-directory; it's effectively "mapped" to the root directory or the new project.

One one I think could work would be something like this:

#setup project
mkdir proj1
cd proj1
git init.
touch .gitignore
git add .gitignore
git commit -m "Initial Commit"

#setup main repo
git remote add origin git@server:proj1.git
git push origin master

# load template repo as separate remote 
git remote add -f template git@server:template.git

# import into current master
# here I guess I have the choice of either:
git merge template/master
# OR
git rebase template/master

Then later on the template project is updated:

+ resources/
  + images/
      3.png  <-added file

I should be able to do a git pull template master to pull the changes from the template and repeat the last merge/rebase steps to integrate into the project.

Is that the correct approach, or is there a better way to do this?

Am I going to run into some trouble with this down that track?


share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The best way to do this is to have a template branch in the template repo. Each clone for the individual projects will have a branch that you make from the template branch. When you want to update from the template, simply fetch and then merge origin/template. The names of the branches are up to you. This is just a suggestion.

I would not recommend rebasing this may cause your projects to go through quite a bit of pain if there, is one day, a large change - especially after a long period of time where a project had a lot of commits. Your rebase will be a very long process.

share|improve this answer
So you're saying do what I suggested in the question.. ? (appart from the rebase) –  Ben Feb 2 '12 at 2:52
Petty much. I'm not sure what else would help. Maybe checkout rerere? –  Adam Dymitruk Feb 2 '12 at 8:42
add comment

Your Answer


