7

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?

7
  • 1
    Remove the vendor folder. And prepare for a world of hurt. Commented Dec 5, 2016 at 23:07
  • 1
    Just version the lock file. An Install on that will give 100% sane results Commented Dec 5, 2016 at 23:08
  • Erm rm .gitignore. What am I missing? Commented Dec 5, 2016 at 23:09
  • @exussum is right. Commented Dec 5, 2016 at 23:12
  • 4
    @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. Commented Dec 6, 2016 at 15:59

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Disk space is cheap. Fixing broken dependencies is less cheap.
2

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.

Comments

0

Do the following to commit vendor directory:

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.