Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
Check out git subtree as talked about here: blogs.atlassian.com/2013/05/… –  Nick May 30 at 14:08
add comment

3 Answers

up vote 10 down vote accepted

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.

share|improve this answer
+1 - Thanks Deckard. I figured Git had something like Submodules, I just didn't know what it was called. I'll definitely take a long look at Phing. I've been wanting a PHP build tool that manages dependencies, runs unit tests, and then deploys to my site. It looks like Phing can probably do all of that. It also looks like it will take a little while to learn. Do you know of any good screencasts for Phing (Google isn't being kind in that regard)? –  VirtuosiMedia May 1 '11 at 8:42
add comment

Git Submodules is a great way of managing git project dependancies. If you're looking for another approach:

Composer can do this all for you. Composer is a dependancy manager for php. It's syntax is of json. It's rather easy and cheap to use.

More about composer:

Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

On the documentation page, you can find an example of how your composer.json file would be constructed:

// Composer.json    

    "name": "acme/blog",
    "repositories": [
            "type": "vcs",
            "url": "https://github.com/composer/hello-world"
    "require": {
        "acme/hello-world": "dev-master"

Once you have your composer.json and composer.lock file created for your project you can then just install your dependancies easily:

composer.phar install or update them: composer.phar update or create a particular project from packagist: composer.phar create-project acmeproject

share|improve this answer
add comment

Recently I started using a tool called Pundle for managing my Project's Dependencies. It supports a PHP Version, PEAR Packages, Git Repositories and SVN Repositories as Dependencies and allows to easily specify them via a "Pundlefile".

You should also configure your Dependencies so that Git/SVN checkouts are put into a directory which is not under Version Control (e.g. "vendor") so you have a fresh start on every checkout and to keep your Project's repository lean.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.