LoginSignup
0
0

More than 1 year has passed since last update.

composer installでprivateリポジトリのソースコードを取得できなかった

Last updated at Posted at 2021-11-09

ただのミスなのですが、備忘も兼ねて記事化

先にまとめ

  • githubにSSHキーを登録してなかったことが原因
  • またはhttpsのアドレスを指定すれば取得できる

どういうエラーか

[RuntimeException]
  Failed to execute git clone --mirror -- 'https://ghp_XXXXXX:***@github.com/sample/sample.git' '/Users/user/.composer/cache/vcs/git-github.com-sample-sample.git/'

  Cloning into bare repository '/Users/user/.composer/cache/vcs/git-github.com-sample-sample.git'...
  remote: Repository not found.
  fatal: repository 'https://github.com/sample/sample.git/' not found

PHPのプロジェクトをgit cloneしてきてライブラリをダウンロードしようとcomposer installした際に発生しました。
どうやらプライベートリポジトリにソースを取得できない模様。
もっと言うならcomposer.jsonに以下のようにリポジトリを書かないといけないパターンです。

"repositories": {
    "sample": {
        "type": "git",
        "url": "git@github.com:sample/sample.git"
    }
}

解決策①

SSHキーを生成してGithubに登録する

手順

①キーを生成

$ ssh-keygen -t rsa

②キーの内容をコピー

名前など指定しない上記のコマンドなら~/.ssh/id_rsa.pubをコピー

③Githubに登録

以下にアクセスしてコピーしたキーを登録
https://github.com/settings/keys

④動作確認

GithubにSSHしてみる
SSHできたらcomposer installも成功するはず

$ ssh -T git@github.com
Hi {user_name}! You've successfully authenticated, but GitHub does not provide shell access.

解決策②

composer.jsonのurlをhttpsのものに変更する。
ユーザー名とパスワード(現在だとアクセストークン)でソースを取得できます。

"repositories": {
    "sample": {
        "type": "git",
        "url": "https://github.com/sample/sample.git" 
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0