Search code examples
gitsvnyii2vendor

Yii2 and git ignore files


I have recently switched from svn to git and i'm a little bit confused.

In the yii2 framework, there are many .gitignore files and i understand the use of these files. but im a bit confused of why is the vendor directory ignored.

The files in there are needed on both my development and production environment.

I used to commit the files in there when using svn, but was i doing it wrong? What is the correct way to do it if i am ignoring the vendor dir.

Do i need to run composer update on both the environment everytime i do a push?


Solution

  • As said by @chris--- it is just a recommandation after all and it is up to you to choose to upload and maintain vendor libraries or not. To get an idea on how it works, go to composer.json inside your app and you'll see something like this :

    "require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": ">=2.0.6",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*"
    },
    "require-dev": {
        "yiisoft/yii2-codeception": "*",
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-faker": "*"
    },
    

    Where you can edit and a set the specific version of any library if needed. Now taking this line :

    "yiisoft/yii2-bootstrap": "*"
    

    Each time you do composer update Composer will just get its repo from packagist.org (see it here), will install the last stable version found (that what "*" means) then will solve its dependencies which can be seen inside \vendor\yiisoft\yii2-bootsrap\composer.json :

    "require": {
        "yiisoft/yii2": ">=2.0.6",
        "bower-asset/bootstrap": "3.3.* | 3.2.* | 3.1.*"
    },
    

    The last line will garante the installation of the last stable version of Twitter Bootstrap 3.3.x.

    Those are the exact libraries with their exact versions downloaded after requesting packagist.org and saved to the vendor folder each time you do a composer update from any machine. If you upload twitter bootstrap 3.3.2 along with your project as example and a team member download it back without having to do composer update then he may find himself stuck in an issue that suppose to be fixed in version 3.3.3 and where he would never needed to know about if he just made the update.

    This is what Composer Team are saying to answer the question : Should I commit the dependencies in my vendor directory? :

    The general recommendation is no...

    ...While it can be tempting to commit it in some environment, it leads to a few problems:

    • Large VCS repository size and diffs when you update code.
    • Duplication of the history of all your dependencies in your own VCS.
    • Adding dependencies installed via git to a git repo will show them as submodules. This is problematic because they are not real submodules, and you will run into issues.

    Also think on how big the extra disk space that should be allocated to github.com if every project had to be uploaded with its vendors. And think on how many exact same copy of twitter bootstrap could be found there.