Dimitris Blog logo
Dimitris Blog
Feb 8, 2014

Git repository inside composer vendors

PHP Composer Git PhpStorm

After creating my first laravel package last week, I discovered a tip I wanted to share with you.

If you have write access to a composer package repository, you have the possibility to continue its development while it is installed as requirement in another project. Let's see how we can accomplish this.

Let's do it!

First, you have to make sure the package is not installed yet. If it is, remove it from the composer.json file and run composer update to uninstall it.

Then, add it to composer.json and run composer update using the following option.

$ composer update --prefer-source

Done!

The composer option --prefer-source is cloning the package's git repository inside the vendor directory. To see your repository changes, or commit, simply chdir to the package's root directory:

$ cd vendor/author/package-name $ git status

Pushing to the right remote

Now, if you try to list the available remote repositories, you will notice that there are two of them: composer and origin. So if you want to push something, make sure you push to origin.

$ git remote composer origin $ git push origin development

A PhpStorm tip

If you use PhpStorm while coding, you are probably working with its awesome git client. In this case you will notice that changes you do to your composer package will not be shown in your project's diff list. Of course they won't, those changes belong to a different repository.

Phpstorm's git client is not able to check two repositories simultaneously

Phpstorm's git client is not able to check two repositories simultaneously

Here is what I do in this case: I just open a second PhpStorm project (File -> Open) and select as directory the root of the package, that is the directory containing your package's composer.json file.

That's it! Happy coding!

Hello World!
Introduction
10 years ago