2

I have two repositories for two websites, but those two websites share the same framework.

I wanted to make a dedicated repository for the framework itself but I'm not sure how would that work.

What I currently do is that I develop the framework within website1 and then copy it to website2 each time I add new features. As you can see it's not very effective...

I would like a separate repository for the framework, but I still need it to be within one of the two websites so I can keep working on it. The most important part is that I need to be able to deploy it to the other website in a simple way

What is the best solution for me? How can this be achieved?

PS: I'm using SourceTree with Bitbucket quit intensively for the past months so I'm fairly familiar with git, but I have never used the command line.

Community
  • 4,922
  • 7
  • 25
  • 37

2 Answers2

2

As long as your framework is limited to a subdirectory of your website, then yes, you can consider your framework a submodule of your website repo, which acts as a "parent" repo.

SourceTree supports submodules (since 1.3), and if your framework is managed in its own repo, you can add it to your website repo.
See "Using submodules and subrepositories"

add submodule in SourceTree

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • +1 Thanks for the answer and for the link! Yes my framework is limited to a subdirectory. However I'm still unsure how will I include my framework in my website2 repo? I guess I could use `git clone` (and then `git pull` to update?) but from what URL/path? I need to be able to work offline. Is [this](http://stackoverflow.com/questions/2519933/git-clone-repo-across-local-file-system) what I need? Thanks! – Community Aug 26 '13 at 12:18
  • @usernotfound no need to clone: simply enter the url and the path (ie the directory within the web repo). SourceTree will clone the submodule repo for you within your parent repo. – VonC Aug 26 '13 at 12:19
  • What I mean is, how do I reuse my framework in another project? I don't need to clone it? – Community Aug 26 '13 at 12:22
  • @usernotfound no, add it as a submodule in that other project. It will be cloned then. If you want to update the same submodule in `web2`, to take into account modifications done in `web1`, simply `git pull` within `web2/framework`, `cd ..`, `git add` and `git commit` (to record the new SHA1 of the framework repo submodule). – VonC Aug 26 '13 at 12:24
0

As you did not mentioned about what language and framework you are working on, in general use cases, creating a git repo for your framework and use as submodules for both the projects are advisable.

Saves time over "copy pasting" and keep commits for your framework away from site specific commits so your commit logs will be cleaner, and could allows others to contribute to your framework and potentially allow the ability to open source your framework.

Ivan Foong
  • 209
  • 2
  • 5
  • Thanks for your answer. It's a website, it has mostly PHP, JS and CSS files. My framework is a custom set of tools, helpers and classes that I re-use from project to project. May I ask why the language matters? – Community Aug 26 '13 at 12:20
  • For specific languages like `ruby` you could use the available external library package management like `rubygems` to modularize your framework and include it into your project instead of using submodules. – Ivan Foong Aug 27 '13 at 02:36