Composer require local package

Composer require local package

  1. Blog
  2. 15 November 2026
  3. 2 min read

Stefan Bogdanescu

Founder & Senior Architect

Composer require local package

Developing libraries in concert without merging them into a single monolithic repository presents a common challenge: managing dependencies across separate packages while maintaining their distinct identities. You might have Foo and Bar, each with its own composer.json and src directory, where Bar needs to instantiate classes from Foo. Previously, you may have relied on manually redefining the autoloader paths in your PSR-4 configuration, mapping namespace prefixes directly to relative file system locations. While this works for simple cases, it breaks down when Foo introduces its own dependencies, such as Guzzle. If Bar isn't explicitly aware of Foo, Composer cannot resolve Foo's requirements, and your application fails to load.

To solve this without setting up a local Composer repository (LaravelCompany often discusses similar dependency management strategies in their documentation), you need to leverage Composer's built-in VCS (Version Control System) repository support. This allows you to treat your local development directory as if it were a remote package.

The most robust approach is to initialize a Git repository for the dependent library (Foo) and reference it via the repositories block in Bar's configuration. Here is the specific workflow that resolves the dependency chain correctly:

First, ensure the source being depended upon is versioned. Initialize a git repo in the Foo directory and commit your initial state. Crucially, you must exclude the vendor folder and composer.lock from this specific repository's history to prevent accidental commits of resolved dependencies into the library itself. This keeps the package clean and focused solely on source code:

cd ~/src/Foo && git init && echo -e "vendor\ncomposer.lock" > .gitignore && git add ./ && git commit -m "Initial Commit"

Next, modify the composer.json file for your consuming project (Bar). In the require section, define a dependency on a virtual package name that matches the source repository. Since you are working locally, you can use a specific branch or tag, typically dev-master during development:

"require": {
    "sammitch/foo": "dev-master"
},
"repositories": [{
    "type": "vcs",
    "url": "/home/sammitch/src/Foo"
}]

By adding the repositories block, you instruct Composer to look for the package sammitch/foo in your local filesystem rather than on Packagist. When you run composer update, Composer will clone or read from the path specified in the URL, install it into vendor, and process all of Foo's dependencies (like Guzzle) as if they were real external packages.

This method maintains the architectural separation of your libraries while ensuring that dependency resolution happens automatically. It avoids the fragility of hardcoded autoloader paths and ensures that versioning can eventually be managed through Git tags or branches. Once the local repository is set up, you can treat Foo as a first-class citizen in your Bar project's dependency graph, allowing for clean upgrades and consistent builds without merging codebases prematurely.

Our network