I am trying hard to understand what is the best practice to use Git with main project development and library development. I will try to explain: I am developing a project and a library simultaneously. Both of them are on the GitHub. And here is my current workflow:
composer update
in the main project, so that the new version of the library will be downloadedThat is too complicated and not right. What is a workout for this problem? I have an option:
Maybe there is some smart and cool method to get rid of this problem, but I don't know about it. Please explain how to do this. Thanks in advance.
P.S. I am using PhpStorm, maybe it has an option that may help us to solve the problem.
If you often update the library that your main project uses you should consider hosting it as a local repository.
You can add a repository using composer CLI (see docs) but it's much more simple to just update the composer.json
file manually.
Open your composer.json
file and find the repositories
attribute (if it's not there create it in the root scope).
It should be an array of objects and every object should have a type (vcs for Version Control System) and an url.
Also add your library to require
. You could use git version tags if you desire, but pointing to dev-master
is a very common practice.
{
"name": "mainproject",
"description": "Main project development",
"repositories": [{
"type": "vcs",
"url": "ssh://[email protected]/library.git"
}],
"require": {
"library/library": "dev-master"
}
}
When you have updated your library (and pushed the changes to the repository) you can simply run composer update library/library
from your main development project to get all changes from your library.