2

Line 61 of the .gitignore file reads

/*.*

which includes itself so the .gitignore file is not committed. Is there a reason behind this?

https://github.com/magento/magento2-community-edition/blob/master/.gitignore

2 Answers 2

0

Obviously not because it already has been committed the repository and as such, will not be ignored anymore.

.gitignore only applies to files that are not added yet, so even if you make changes to the file, Git will show it as unstaged changes and they will be included in a commit after staging.

2
  • Okay, I was wondering because I installed the project via composer so the .gitignore file was untracked. I'll just add it "git add -f .gitignore".
    – notebox
    Mar 9, 2016 at 14:45
  • From your perspective it makes sense that it's ignored. See my answer below. Magento copies the files from a vendor package to your root on installation and from that moment the .gitignore works. It doesn't need to be included, as next time you run composer install with a missing installation, it will be copied again. See more below. Mar 9, 2016 at 22:11
0

What Magento 2 basically does, it ignores a lot and then allows some specific files again. So after installing Magento 2, you probably only have the composer files to commit to your repository + a README. On composer install, Magento 2 identifies whether it should install the application (if already in there, nothing will happen), and so it does for the .gitignore file. It basically copies it to your root and it's used to protect you from adding all these application files to your repository.

So a lot is ignored by default, but some files NOT ignored are:

  • composer.json
  • composer.lock
  • README.md

The .gitignore file is inserted in the folder again after composer install is ran. Composer defines the requirements and also after composer install install the application if needed.

I think a lot of people would make some adjustments, so they can also save some extra files in their repository for easier customization, e.g. .gitignore & .gitattributes. Besides that, some will decide to version control app/etc/config.php.

1
  • I create a project via "composer create-project" and then commit all of the changes to a git repo. Everything works fine for me until I do a "git clone", "composer install" of this new repo. For me the .gitignore file is not created when I do composer install so all of the files are added to my working directory so the only way to solve it seems to be to force add the .gitignore file.
    – notebox
    Mar 10, 2016 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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