157

For example I want to require:

{
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/google/google-api-php-client.git"
    }
  ],

  "require": {
    "google/apiclient": "v1-master"
  }
}

In this example I try require google/apiclient on branch v1-master. I get error:

  [UnexpectedValueException]                                                        
  Could not parse version constraint v1-master: Invalid version string "v1-master"

3 Answers 3

262

You need to prefix all dev branches (= non tagged) by dev-.

To install the branch you need, use:

composer require google/apiclient:dev-v1-master

See composer docs.

5
  • I am trying that on a windows machine but unable to find correct command to run composer to download a package from the git repository. So you please help on this? Sep 9, 2019 at 3:09
  • 1
    Add the 'dev-' prefix is ​​only in the composer command. Do you don't need to change anything in repository branches name Jan 24, 2020 at 18:24
  • Couldn't reinstall updated branch even with --no-cache so I used this: composer require google/apiclient:dev-v1-master#COMMITHASH
    – M Rostami
    Jun 17, 2020 at 7:59
  • 1
    Can somebody explain why 'dev-' is needed in branch name to checkout branches which are not in development?
    – HEYDANNY
    Jan 22, 2021 at 17:20
  • 1
    It's just composer convention. See "If you alias a non-comparable version (such as dev-develop) dev- must prefix the branch name. You may also alias a comparable version (i.e. start with numbers, and end with .x-dev), but only as a more specific version. For example, 1.x-dev could be aliased as 1.2.x-dev." - getcomposer.org/doc/articles/aliases.md#branch-alias Jan 22, 2021 at 17:27
88

this will work :

{
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/google/google-api-php-client.git"
    }
  ],

  "require": {
    "google/apiclient": "dev-BRANCH_NAME"
  }
}

so pattern is "dev-*", if you branch name is "bug-fix" then "dev-bug-fix"

with command line :

composer require google/apiclient:dev-BRANCH_NAME
1
  • 12
    If you forked the main repo do not change vendor name in the require part. Fork: "url": "https://github.com/your-username/google-api-php-client.git" but require stays: google vendor. Oct 20, 2019 at 23:05
3

I was trying to the same for a different Google repository which contains several packages and it took me some time to figure it out. Therefore I am sharing my solution below.

My goal is to pull latest google/cloud-compute from https://github.com/googleapis/google-cloud-php.git within master branch.

Following steps worked for me:

  1. Clone the repository
git clone https://github.com/googleapis/google-cloud-php.git google-cloud-php
  1. Set composer.json to use the right package from local folder:
{
    "repositories": [
        {
            "type": "path",
            "url": "/Users/USERNAME/projects/google-cloud-php/Compute"
        }
    ],

    "require": {
        "google/cloud-compute": "dev-master"
    }
}

Please note that in step 2 the url is pointing to the Compute subfolder where the actual google/cloud-compute package exists.

My solution could be easily tweaked for any branch, you would just need to git checkout the appropriate branch in step 1 and then change 'dev-master' to 'dev-YOUR_BRANCH' in step 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.