search
HomeDevelopment ToolscomposerDoes the content downloaded by composer need to be submitted to git?

The following tutorial column of composer will introduce to you the question of whether the content downloaded by composer needs to be submitted to git. I hope it will be helpful to friends who need it!

Specific question:

I would like to ask all the students who use Composer, will you submit the content of the files downloaded through Composer to Git?
I saw the article Should I Commit the dependencies in my vendor directory on the official Faq. Some people suggested not to submit it to Git. So how should I deal with the problem of re-composer install when switching branches? If the vendor is submitted to the repository, how should the .git folder in the package be handled?

*Correction composer update should be composer install

Solution:

In fact, whether it is branch development or deployment to the production environment , no matter how you write the wildcard rules for the version number in composer.json, what we are most concerned about is always the most fundamental content: At the time of development, what is the specific version number of all the dependent libraries we used?

This content is supported by the composer.lock file. By maintaining lock files, composer itself records the specific versions of all dependent libraries in the project after any changes are made to the dependent libraries. Please read the documentation about this file (https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file).

You should always submit the composer.lock file to the repository, and after switching branches or deploying, use composer install to install the specific dependency versions specified in the lock file.

In this sense, it is correct whether you submit the vendor directory to the main repository. It is a trade-off choice whether to submit or not:

If submitted:

Advantages: "Pull and use" convenience.

Disadvantages: Duplication of information. Because of the specific version you developed at the time, the lock file has been recorded. In other words, the vendor folder expresses the same thing.

Disadvantage: Risk of introducing inconsistency. Because although Composer ensures that the lock file is consistent with the vendor directory, submitting it to the git repository is a manual act after all. You can't guarantee that you won't fall behind one of the two.

If you do not submit, the advantages and disadvantages will be reversed. Not to be repeated again.

My thoughts are: I suggest you stick to the idea of ​​"correctness over ease of use". My suggestion is not to submit to the vendor, but just use the lock file to maintain the version of the dependent library at the time of development.

If you submit, please be sure to follow the following two guidelines:

(1) Be sure to ensure that the submission of the two files vendor and composer.lock is synchronized. If one is mentioned, the other must be mentioned.
Any development, if only one of the commits is submitted, must be held accountable.
The reason for this is: Although we submit to the vendor to ensure that it is available immediately after pulling it, git has a partial checkout function - for a Composer project, I have the right to follow the convention of the Composer project and not check out vendor directory, but pull down the actual code and then do a composer install. You can't say I'm wrong.
(If anyone says this is wrong, I support you to expose your unscrupulous company and technical director on SF and Zhihu every minute)

(2) Be sure to follow Composer’s instructions for submitting the vendor folder Suggestion (https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md), ignore all .git directories of sub-library, and only submit the ones in vendor Code of practice.
Believe me, the actual code in the vendor and the management files of the git library itself under vendor/**/.git are definitely related to the above-water part and the underwater part of the iceberg. If you don't ignore it, people will die. It's not an exaggeration.

It must also be pointed out that during branch development, even if you do not synchronize the vendor through the repository, but only synchronize composer.lock, it will not cause a waste of time.

When switching between two branches, it is nothing more than switching back and forth between two specific versions. Composer itself caches all downloaded libraries. The composer install after each branch pull will definitely hit all caches, without repeatedly consuming download time.

The above is the detailed content of Does the content downloaded by composer need to be submitted to git?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete
Composer: Streamlining PHP Project DevelopmentComposer: Streamlining PHP Project DevelopmentApr 15, 2025 am 12:08 AM

Composer simplifies PHP project development steps include: 1) adding dependencies, such as adding "laravel/framework":"^8.0" in composer.json; 2) automatically loading, generating an autoload.php file by defining the namespace and classpath; 3) optimizing performance, using composerdump-autoload-o and composerinstall--no-dev-optimize-autoloader commands. Through these steps, developers can be more efficient and avoid common mistakes.

Composer Credentials: What Makes Someone a Composer?Composer Credentials: What Makes Someone a Composer?Apr 14, 2025 am 12:13 AM

The key elements of becoming a composer include: 1. Mastering music theory, 2. Being creative and original, 3. Having technical skills, 4. Being able to express emotions and tell stories, 5. Understand cultural and historical background, 6. Accumulating practice and experience, these elements together constitute the composer's identity and ability.

The Path to Becoming a Composer: A Practical GuideThe Path to Becoming a Composer: A Practical GuideApr 13, 2025 am 12:11 AM

The steps to becoming a composer include: 1. Master the basic elements of music, such as notes, rhythm, harmony, and melody; 2. Select appropriate technical tools, such as AbletonLive; 3. Understand the process of composing, including inspiration acquisition, conception, writing, modification and improvement; 4. Start with simple melody creation and gradually try complex techniques such as harmony; 5. Solve common problems through debugging techniques, such as note selection and rhythm arrangement; 6. Apply performance optimization and best practices, such as using templates, version control, and collaboration.

Composer: The Key to Building Robust PHP ApplicationsComposer: The Key to Building Robust PHP ApplicationsApr 12, 2025 am 12:05 AM

Composer is a key tool for building robust PHP applications because it simplifies dependency management, improves development efficiency and code quality. 1) Composer defines project dependencies through composer.json file and automatically downloads and manages these dependencies. 2) It generates a composer.lock file to ensure that the dependency version is consistent and automatically loaded through vendor/autoload.php. 3) Examples of usage include basic usage such as adding log libraries, as well as advanced usage such as version constraints and environment variable management. 4) Common error debugging techniques include handling dependency conflicts and network problems. 5) Performance optimization suggestions include using composer.lock file and optimizing automatic loading.

Composer Expertise: What Makes Someone SkilledComposer Expertise: What Makes Someone SkilledApr 11, 2025 pm 12:41 PM

To become proficient when using Composer, you need to master the following skills: 1. Proficient in using composer.json and composer.lock files, 2. Understand how Composer works, 3. Master Composer's command line tools, 4. Understand basic and advanced usage, 5. Familiar with common errors and debugging techniques, 6. Optimize usage and follow best practices.

What is a composer doing?What is a composer doing?Apr 08, 2025 am 12:19 AM

Composer is a dependency management tool for PHP, used to declare, download and manage project dependencies. 1) Declare dependencies through composer.json file, 2) Install dependencies using composerinstall command, 3) parse the dependency tree and download it from Packagist, 4) generate the autoload.php file to simplify automatic loading, 5) optimize use includes using composerupdate--prefer-dist and adjusting the autoload configuration.

What is App composer?What is App composer?Apr 07, 2025 am 12:07 AM

AppComposer is a tool for building and managing applications. 1) It simplifies application development and improves efficiency by dragging and configuring predefined components. 2) Developers can define components, combine interfaces, define business logic, and ultimately render the application. 3) Support basic and advanced usage, such as task management and conditional rendering, helping to build flexible applications.

What is a composer used for?What is a composer used for?Apr 06, 2025 am 12:02 AM

Composer is a dependency management tool for PHP. The core steps of using Composer include: 1) Declare dependencies in composer.json, such as "stripe/stripe-php":"^7.0"; 2) Run composerinstall to download and configure dependencies; 3) Manage versions and autoloads through composer.lock and autoload.php. Composer simplifies dependency management and improves project efficiency and maintainability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment