4
votes

Can I setup .gitignore in such a way to allow Composer dependencies (the vendor directory) to live inside my repository?

Composers officially recommends that you "should not" do this. And it provides three reasons (https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md):

  1. Large VCS repository size and diffs when you update code.
  2. Duplication of the history of all your dependencies in your own VCS.
  3. 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.

All these three reasons do not matter to me. Also it may be possible that reason three could be obviated by a clever .gitignore.

If it is necessary for me to state a motivation for this question then my motivation is: CocoaPods does it this way and I like how CocoaPods works.

What exactly should I do in .gitignore to achieve this?

3
Remove the vendor folder. And prepare for a world of hurt. - Jordan Soltman
Just version the lock file. An Install on that will give 100% sane results - exussum
Erm rm .gitignore. What am I missing? - thespinkus
@exussum is right. - Jordan Soltman
@exussum, composer install with a versioned composer.lock "will give 100% sane results"… provided all of the dependencies defined therein are still available and can be retrieved. There are ways it can still fail, and there are situations where one might actually want to include vendor/ in their repository. - Chris

3 Answers

3
votes

Simply remove any reference to /vendor from your .gitignore file. Then add and commit the vendor files.

Just be prepared to add 100+ megs of vendor library files to your repository.

1
votes

In my case the following worked:

  1. Remove vendor from .gitignore
  2. Clear git's cache: git rm -r --cached .
  3. Add files: git add .
  4. Commit files: git commit.
  5. Push files to main repo.
0
votes

Do the following to commit vendor directory:

git add vendor 
git commit -m "Added vendor directory to source control"