Php Composer error when trying to install certain branch: The requested package … exists, but these are rejected by your constraint

Keywords: git github composer-php

Question: 

Summery

I'm trying to install a package from a private repository on a certain branch (on github). Before the package could be installed from another branch. That wasn't a problem. But now, no matter what I do, the following error is thrown:

The requested package vendor/repo dev-new_mybranch exists as vendor/repo[1.0.0, dev-mybranch] but these are rejected by your constraint

The following things work fine:

  • I have a repository for my own module (vendor/repo)
  • There I have a certain branch called mybranch
  • I can include this new branch in my composer.json with
"require": { 
   "vendor/repo": "dev-mybranch"
   ...
},

This works perfectly fine.

The following things DON'T WORK:

  • Then I have a new branch in my modules' repository: new_mybranch
  • I want to include this branch instead of the old branch, so in my composer.json I use the following:
"require": { 
   "vendor/repo": "dev-new_mybranch"
   ...
},
  • After running composer update I get the following error:
The requested package vendor/repo dev-new_mybranch exists as vendor/repo[1.0.0, dev-mybranch] but these are rejected by your constraint

What I already tried to solve this error

  • Clear composer cache: composer clearcache
  • composer update -v doesn't do the trick either. There is no more information than the text in the error.
  • I tried branch aliases, but this didn't work either.
  • There is another method to require branches: Instead of "dev-new_mybranch" one could use "new_mybranch.x-dev". Apparently, this should be used, if the branch name could also be interpreted as a version name. But this way wont't work either.
  • I tried to start a whole new project (without git and with no vendor-folder so far, since that was recommended in another thread). Then I used composer install, but still I get the same error as a result.

Answers: