How to require a fork with composer

here is my composer.json, i want to use Nodge’s fork of lessphp project on Github

 "repositories": [{
    "type": "package",
    "package": {
        "version": "dev-master",
        "name": "nodge/lessphp",
        "source": {
            "url": "https://github.com/Nodge/lessphp.git",
            "type": "git",
            "reference": "master"
        },
        "autoload": {
            "classmap": ["lessc.inc.php"]
        }
    }
}],
"require": {
    "php": ">=5.3.3",
    "nodge/lessphp": "dev-master"
},

But i have this error when i make update :

  • how to easily debug a symfony bundle shared across project
  • composer update not pulling latest dev-master
  • How to provide access to a git repository that is used by Composer
  • How can we use a self hosted git repository with composer?
  • Test and Debug Composer plugins
  • Git workflow for composer package?
  • nodge/lessphp dev-master -> no matching package found.

    I don’t know how to require it correctly this fork…

    Any suggestions ?

  • Can a GIT branch have a subset of data?
  • Download single files from GitHub
  • Version control approach for inconsistent changes
  • Pushing to multiple github account
  • git push showing “Everything up-to-date” but compare shows differences
  • How to add Github raw repositories to Sonatype Nexus as Proxy repository?
  • 6 Solutions collect form web for “How to require a fork with composer”

    The most common (and easier) way of doing it is using a VCS repository.

    All you have to do is add your fork as a repository and update the
    version constraint to point to your custom branch. Your custom branch
    name must be prefixed with dev-.

    Example assuming you patched monolog to fix a bug in the bugfix branch:

    {
        "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/igorw/monolog"
            }
        ],
        "require": {
            "monolog/monolog": "dev-bugfix"
        }
    }
    

    Note that you don’t change the require statement except to specify your bugfix branch. You still reference the upstream package (monolog/monolog), not your personal fork (igorw/monolog). You can read details in the docs

    Using VCS works:

    "name": "test/test",
    "repositories": [{
        "type": "vcs",
        "url": "http://github.com/Nodge/lessphp"
    }],
    "require": {
        "leafo/lessphp": "dev-master"
    },
    

    But if I require a module that has this composer.json, it doesn’t work. It installs the original project, not the fork.

    Example

    "name": "example/example",
    "require": {
        "test/test": "dev-master"
    },
    

    I should mention again the repository. Is that normal?

    If you can’t get @Neilime answer to work for you, make sure your fork uses a different branch.

    For example push your changes to a branch on your fork called my-bugfix. Your composer file will look like:

    "repositories":
    [
        {
            "type": "vcs",
            "url": "http://github.com/yourname/packageName"
        }
    ],
    "require": {
        "owner/packageName": "dev-my-bugfix"
    },
    

    According to the Composer documentation
    http://getcomposer.org/doc/05-repositories.md#vcs, it’s enough to
    specify the original repository (not the fork) in the require (“nodge/lessphp” in your case). Composer will then install YOUR fork (look at the code in the vendors)

    I usually add a “dist” node to the package definition.
    I never had a problem using it this way.

    I can’t remember where I got this trick from, though, for any further explanations.

    {
        "repositories": [
            {
                "type": "package",
                "package": {
                    "version": "dev-master",
                    "name": "nodge/lessphp",
                    "source": {
                        "url": "https://github.com/Nodge/lessphp.git",
                        "type": "git",
                        "reference": "master"
                    },
                    "autoload": {
                        "classmap": ["lessc.inc.php"]
                    },
                    "dist": {
                        "url": "https://github.com/Nodge/lessphp/archive/master.zip",
                        "type": "zip"
                    }
                }
            }
        ],
        "require": {
            "nodge/lessphp": "*"
        }
    }
    

    Ok, so I did what the documentation said and it works… so how do i push back any changes to github back to my fork seeing that composer didn’t create a git repo in the package folder. Do i start by actually initializing the repo and pointing it to the fork again or composer has some param that i needed to pass for it to create the fork’s repo in the vendor/package folder?

    My goal is to push any changes i do to the fork then do a PR later, but there is no git repo in the package folder.

    Git Baby is a git and github fan, let's start git clone.