Php – Git Project Dependencies on GitHub

dependenciesgitgithubPHP

I've written a PHP framework and a CMS on top of the framework. The CMS is dependent on the framework, but the framework exists as a self-contained folder within the CMS files. I'd like to maintain them as separate projects on GitHub, but I don't want to have the mess of updating the CMS project every time I update the framework. Ideally, I'd like to have the CMS somehow pull the framework files for inclusion into a predefined sub-directory rather than physically committing those files.

Is this possible with Git/GitHub? If so, what do I need to know to make it work? Keep in mind that I'm at a very, very basic level of experience with Git – I can make repositories and commit using the Git plugin for Eclipse, connect to GitHub, and that's about it. I'm currently working solo on the projects, so I haven't had to learn much more about Git so far, but I'd like to open it up to others in the future and I want to make sure I have it right.

Also, what should my ideal workflow be for projects with dependencies? Any tips on that subject would also greatly appreciated. If you need more info on my setup, just ask in the comments.

Best Answer

First, if you really want to use git for this, then consider using its Submodule functionality:

Git's submodule support allows a repository to contain, as a subdirectory, a checkout of an external project. Submodules maintain their own identity; the submodule support just stores the submodule repository location and commit ID, so other developers who clone the containing project ("superproject") can easily clone all the submodules at the same revision. Partial checkouts of the superproject are possible: you can tell Git to clone none, some or all of the submodules.

The linked page contains a detailed discussion including examples of how to use it exactly.

That said, I would recommend not to use your version control system for dependency management and rather start using a build tool that can handle these things for you, such as Maven or Ant. There is even a PHP-specific build tool in development called Phing, but I haven't used it myself yet. It is mentioned in an article that discusses your question: Version Control != Dependency Management.

The reason build tools may be a better fit in the long run is because they often also support different repository types, external libraries (and different locations) and extensive checking. If you however just want to integrate these two libraries and don't want any additional hassle, the submodule approach is probably sufficient.

Related Topic