Quick reference for composer

If you struggle to remember and memorize how to do various things using composer, then here is a quick-reference to help you out.


By. Jacob

Edited: 2023-11-02 22:35

A short reference to help myself to remember – maybe you will find it useful too! :-)

Note. Depending on your configuration, you may need to run these commands with sudo -u www-data in front of them. This will run the command as the www-data user.

Add a git repository:

composer config repositories.<optional name for composer.json> git https://github.com/<company or user>/<repository name>

Require a package from GitHub:

composer require <company or user>/<repository name>:dev-<branch name>


composer require mycompany/myrepositoryname:dev-main

Or a specific branch:

composer require mycompany/myrepositoryname:dev-version-2.1

This will also work for repositories you added from GitHub.

Remove a composer package:

composer remove mycompany/myrepositoryname:dev-version-2.1

All branches are prefixed with dev-, so a branch, even the main one, will become dev-branchname; this is a bit unintuitive at first, because where is the "dev-" part coming from? Well, well, that is just how it is!

Install dependencies:

composer install

Installs stuff listed in composer.json, but does not update anything.

Update a composer package:

composer update mycompany/myrepositoryname

Update all packages from vendor:

composer update mycompany/*

Update all packages:

composer update

Tell us what you think:

  1. The could not reset changes error might indicate a problem with file permissions, and you may have to fix the permissions and re-install the package via composer to fix it.
  2. How to fix a problem with composer in Docker that results in: failed to open stream: No such file or directory error for InstalledVersions.php.
  3. How to install and use composer locally, without the need to write sudo all the time.

More in: Composer