How can I use git for projects templates?
I would recommend creating a branch specifically for any template changes you want to make. But make sure you start it from one of the earlier commits, so you don't get project-specific changes to your template. Something like git checkout -b template_changes EARLY_COMMIT_SHA
.
Then any template changes you have already made, you can cherry-pick in: git cherry-pick TEMPLATE_CHANGE_SHA
.
Any future changes to the template you would like to make could be done on the template branch and merged into other branches of the project; but if you are far along enough, you may want to switch to the template project.
To push your template changes from the project into the template git repository, you could do git format-patch SHA_FROM_WHERE_TEMPLATE_BEGAN
. This will create a bunch of patch files that you'll have to copy to the template repo and run git apply 0001-... 0002-...
to apply the patches, but that's not very fun.
A more git-fu thing to do would be to add the template repo in the project repo git remote add template /path/to/template/repo
. You may have to play with the -t
or -m
options or the command git remote set-head template template_branch:master
(or something) if the template branch exists. Then you should be able to push your changes to the template repo with git push template template_branch
. If the template_branch's head isn't set property, you may have to git push template template_branch:master
.
Hope this works out for you. And have fun!