I keep forgetting the best way to do this, so thought it best to write it down.
Suppose you are building a library and an example project that implements it. You can do this in a single repository with an example folder, for small examples.
But for larger examples you might want to use a separate repository, with it’s own issues and documentation.
This can make it a hassle to work with the library and keep the project in sync.
Let’s say these are
myproject which is using the library. Let’s assume you’re using PHP and Composer.
mylibrary is at version 0.1 but there are newer commits in the
Require a Git repository
$ cd myproject $ composer config repositories.me vcs https://github.com/me/mylibrary $ composer require me/mylibrary:0.1 --prefer-source
--prefer-source means Composer will install from
source if there is one, the result is a git repository.
Switch to the develop branch
Once installed it’s then easy to switch to any other branch you want to work on:
$ cd vendor/me/mylibrary; git switch develop
You don’t have to register the repository with packagist if you follow this workflow! As a bonus when after you run
composer update in
myproject the mylibrary directory sticks with the branch.