What is composer.lock, and should you commit it?
composer.json says which versions you accept. composer.lock records which versions you actually got: the exact release of every package in your project, including the dependencies of your dependencies.
composer.json and composer.lock
In composer.json you write constraints, such as "laravel/framework": "^13.0". That line accepts any 13.x release from 13.0.0 up to, but not including, 14.0.0. It does not say which one you are running.
When Composer resolves those constraints, it picks one version of every package that fits all of them together and writes the result to composer.lock. A typical Laravel application lists a few dozen packages in composer.json and well over a hundred in composer.lock, because every package brings its own requirements.
What is inside the file
composer.lock is plain JSON. The parts that matter most:
packagesandpackages-dev: one entry per installed package, with its exact version, the commit or archive it was installed from, and the package's own requirements.content-hash: a hash of the parts of composer.json that affect the result. Composer compares it with your current composer.json to see whether the lock file is out of date.platform: the PHP version and extensions your own composer.json requires, andplatform-overrideswhen you setconfig.platformto pretend a different PHP version during updates.minimum-stability,prefer-stableandstability-flags: the settings that decide whether beta and dev releases may be installed.
The file contains package names, versions and download addresses. It does not contain your code, and credentials belong in auth.json, not here. It can name private packages and private repository addresses, so treat it like the rest of your repository.
When Composer reads it and when it rewrites it
composer installinstalls exactly the versions in composer.lock, even when newer releases exist. Without a lock file, it resolves the constraints and creates one.composer updateresolves the constraints again, installs the newest versions they allow and rewrites composer.lock.composer update vendor/packageupdates only that package. Add-W(--with-all-dependencies) when its dependencies need to move too.composer require vendor/packageadds the package to composer.json and updates composer.lock for it.
If you edit composer.json by hand and run composer install, Composer warns that the lock file is not up to date with the latest changes in composer.json. Run composer update vendor/package for the package you changed. composer update --lock only refreshes the hash, without changing any versions; use it when the change does not affect which packages are installed.
Should you commit composer.lock?
For an application, yes. The lock file is what makes your laptop, your CI and your production server run the same versions. A deploy then runs composer install --no-dev --optimize-autoloader and gets exactly what you tested. Without the lock file, every deploy resolves the constraints again and can pick up a release nobody has tested.
For a library, it matters less. Composer only uses the lock file of the project at the top: when someone installs your library, your composer.lock is ignored and their constraints decide. Many libraries leave the file out so their test suite runs against the newest versions their constraints allow. Committing it is also fine, as long as CI tests the newest versions as well.
Merge conflicts in composer.lock
Do not fix them by hand: the content hash and the package list have to agree. Take the version of composer.lock from the branch you are merging into, then repeat the Composer commands your own branch made, such as composer require vendor/package or composer update vendor/package. Composer writes a consistent file again.
Your lock file as an inventory
Because composer.lock lists every installed version, it is the file to check when you want to know what is out of date or vulnerable. composer outdated --locked and composer audit --locked both read it directly. See how to find outdated Composer packages and what composer audit checks.