gitgit-submodules

Single file as Git submodule


I'm trying to ascertain best-practices for shared code amongst Git repositories.

So far, I've obviously come across submodules which seem like they - almost - fit the bill. My project is a PHP MVC framework with a simple structure:

Where app is a folder containing application-specific controllers, models, views etc. while core contains those of general use, e.g. a login controller. The core.php file itself is the global handler for all requests.

As such, the shared code amongst all of my deployments of this MVC framework is core.php and core.

I can see how it is possible to turn core into a Git submodule, but not core.php.

Is this even possible? Do I need to re-architecture my framework so that core.php resides inside the core folder so I can make the whole folder a submodule, or is there a better way?


Solution

  • Perhaps you are best off maintaining core.php and core in a separate repo, and then using it as a remote. Then you can manage it by pulling it into any project it is used. In order to do this, just start the new project as a separate git repo, and then pull in the 'core' repo as a subtree.

    This chapter shows you how to do it:

    Updated Reference: http://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_subtree_merge Original Reference: https://git-scm.com/book/en/v1/Git-Tools-Subtree-Merging

    It is a little better for you than the setup advised in the previous section of the book (6.6).

    Look at it; it might be helpful.