Pragmatism in the real world

Converting a Composer dependency to git for editing

I’m adding a new feature to ZF’s Problem-Details component and it’s easiest to do this within the context of the application I’m developing.

The component lives in vendor/zendframework/zend-problem-details and was installed using composer require so doesn’t have its own git repository as the distribution zip file was used to install it.

To change it to a git repository, we can use the --prefer-source option and specify a branch like this:

$ composer require --prefer-source zendframework/zend-problem-details:dev-master

I now have a git checkout of the component with two remotes: origin and composer. I changed origin to my fork and then create a branch to work on:

$ cd vendor/zendframework/zend-problem-details
$ git remote rm origin
$ git remote add origin git@github.com:akrabat/zend-problem-details.git
$ git checkout -b my-new-feature

We’re now off the races and I can easily develop my new feature and push to origin as normal and then hopefully raise a PR.

3 thoughts on “Converting a Composer dependency to git for editing

  1. Can you list your git remotes before "git remote rm origin" and after the "git checkout". Whats the point of having a remote for Composer (which I assume is pointing to the same thing Origin points to initially). For development dont you want the –prefer-source to be the new repo youre doing work on, namely github.com:akrabat/zend-problem-details.git ?

    1. Dgurba,

      My fork doesn't have a packagist registration so composer require won't find it unless I mess with composer.json. Hence it's easier to –prefer-source on the real version and then just swap the origin remote to point at my fork. It follows that my fork is already synced to the main version.

Comments are closed.