What is the preferred structure of a Magento 2 project under VCS?

Shortish term, we are looking to separate files that need customization. E.g. if people need to modify index.php, work out how to separate the standard file Magento ships from the need of local customizations. Once achieved, it is possible to have a "one true .gitignore for all projects can use". That is, easy to commit whole project directory to Git with .gitignore of everything that "composer install" will fetch for you (and everything "composer update" will replace when installing a patch or upgrade).

Longer term, the goal is to shorten .gitignore as much as possible. E.g. push more into modules under the 'vendor' directory.

Then

  1. For everything you don't want to share across projects, leave it under app/code and committed in the main project repo.
  2. Everything locally developed you want to share across projects more easily, put in a separate GIT repo and install via composer so it ends up under 'vendor'. (Could be a local composer repo, or just install straight from GIT.)

That way you can still git commit the whole project tree from the top down, capturing the composer.json and composer.lock files (committing just app/code does not). The .gitignore will exclude the 'vendor' directory and other files not wanted.

This gives you the best of both worlds mentioned in the other discussion. The current pain is the length and complexity of the .gitignore file, and patch installation currently wipes out some local customization (e.g. in index.php). Short term workaround - remove index.php from .gitignore, and when you install a patch check to see what changes you lost (git diff) and reapply them manually.


There is an easy Solution for your override Problem: don't change core Files ;) Magento is based on extending the Code and not changing it.

First thing is, you should not put your whole app/code folder in one vcs Repository. Each Magento Component (Module, Theme, etc...) should be a repository itself.

If you want to change/extend the frontend, you should create a new theme and treat this theme as your grunt project, not the whole Magento2 Instance.

To install your theme in your Project you can easily pull it in via composer directly from your vcs repository


Ok, looks like I found a better solution for what I was trying to achieve. In the composer.json, it is possible to specify which files should be ignored by the Magento Composer Installer. If I don't want my Gruntfile.js to be overridden, I can simply specify it with the following configuration:

"extra": {
    "magento-deploy-ignore": {
        "magento/magento2-base": [
            "/Gruntfile.js",
            "/package.json"
        ]
    }
}

I am now able to extend the standard installation to fit my needs.