I have the following in my Laravel 5.1 projects composer.json to add a public github repository as a dependency.
...
"repositories": [
{
"type": "package",
"package": {
"name": "myVendorName/my_private_repo",
"version": "1.2.3",
"source": {
"type" : "git",
"url" : "git://github.com/myVendorName/my_private_repo.git",
"reference" : "master"
},
"dist": {
"url": "https://github.com/myVendorName/my_private_repo/archive/master.zip",
"type": "zip"
}
}
}
],
"require": {
....
"myVendorName/my_private_repo": "*",
},
...
This works as long as the repository is public. Now I've set this repository to private. The git credentials I use for pulling/pushing to 'my_private_repo' are the one of a colaborator of the project. How can I achieve that composer pulls from that private repository when I run composer update or composer install?
My Answer:
To add a private GitHub repository as a Composer dependency, you can use the following steps:
1. Generate a personal access token on GitHub:
- Go to your GitHub account settings.
- Click on "Developer settings" > "Personal access tokens" > "Generate new token".
- Give your token a name, select the scopes needed (e.g., repo), and generate the token.
- Copy the generated token as you will need it in the next step.
2. Add the personal access token to your Composer configuration:
- Run the following command in your terminal:
composer config --global github-oauth.github.com
- Replace `
3. Update your composer.json file:
- Modify the "repositories" section in your composer.json file to include the private GitHub repository:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/myVendorName/my_private_repo"
}
],
- Update the "require" section to include the private repository as a dependency:
"require": {
"myVendorName/my_private_repo": "dev-master"
},
4. Run composer update or composer install:
- Run the following command in your terminal to update your dependencies:
composer update
- Composer will now use your personal access token to authenticate and pull the private repository as a dependency.
By following these steps, you should be able to add a private GitHub repository as a Composer dependency in your Laravel project.
Rate this post
5 of 5 based on 7013 votesComments