In this tutorial I will show you how to integrate a GitHub private repository to your composer.json file, in order to install it as a dependency.

Generate Github Token

  1. Go to https://github.com/settings/tokens
  2. Generate a token with a custom name you want, like “CodealistBundle Composer”
  3. Copy the generated token

Edit composer.json

  1. Look for your “repositories” section, and if you don’t have it, added.
  2. Now go to edit your “config” section in order to add your github token, asuming that “…” is the content of your “config” section before editing.
  3. If you want to specify a branch, for example the branch “bug-fixing”, you need to add to the require section the composer repository name (specified within your composer.json file) and the branch name with the prefix “dev-” as it follows:

     

Now run a composer install command and you’ll be able to download your private repository as a composer dependency from any environment.

In conclusion, you need to generate a GitHub Token to grant access to your project to download a specific private repository.

Leave a comment