LoginSignup
102

More than 3 years have passed since last update.

remote: Repository not found.となった時の対応方法

Last updated at Posted at 2019-06-13

事象:SourceTreeでGitHubからリポジトリをCloneしたら怒られた

  • 環境
    • Winsows10 64bit
    • SourceTree v3.0.8
      • 既に他のアカウントでGitHubからcloneしたリポジトリがある
コマンド: git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks -c credential.helper= -c credential.helper="C:/Users/ponsuke/AppData/Local/ATLASS~1/SOURCE~1/GIT_EX~1/GIT-CR~1.EXE" ls-remote https://github.com/ponsuke/repository.git
出力: 
エラー: remote: Repository not found.
fatal: repository 'https://github.com/ponsuke/repository.git/' not found

https://github.com/ponsuke/repository.git/

原因:認証できないから

Githubにhttpsでgit cloneできない時やったこと - Qiita

対応:ユーザ名とパスワードを指定してCloneする

Cloneするリポジトリを以下の形式で指定する

https://{ユーザ名}:{パスワード}@github.com/ponsuke/repository.git

やってないけどremote accountリンクから設定してもできそう
image.png

GitHubの2段階認証を設定している場合

  1. GitHubにログイン > 右上にある自分のアイコンをクリック > [Settings]
  2. [Developer settings] > [Personal access tokens] > [Generate new token]ボタンでトークンを生成する
  3. Cloneするリポジトリを以下の形式で指定する
2段階認証を設定している場合
https://{ユーザ名}:{トークン}@github.com/ponsuke/repository.git

事象 : 既にCloneしていたGitHubのリポジトリをフェッチしたら怒られた

$ git fetch --all --prune
Fetching origin
remote: Repository not found.
fatal: repository 'https://github.com/ponsuke/repository.git/' not found
error: Could not fetch origin

原因 : Windows Credential Managerがおかしいから

なぁぜか、昨日までフェッチできていたのにぃ・・・

Gitのログインに必要なユーザ名とパスワードが、Windows Credential Manager (資格情報マネージャ)に格納され、Git のアカウントを複数利用した場合に問題が発生するということが書いてあった。
Github へ push しようとしたら Repository not found というエラーが出るようになった

そういえば、さっき違うGitHubアカウントでクローンとかやったなぁ・・・

対応 : システム全体用の設定を修正する

# 1. システム全体用のconfigをエディタで開く
$ git config --edit --system
# 2. エディタで以下を削除する(※[credential]にhelper以外の設定があったら[credential]は残す)
[credential]
    helper = manager
# 3. 保存してconfigを閉じる
# 4. もう一回フェッチしたらできた
$ git fetch --all --prune
Fetching origin

$

原因:認証できないから

先に書いた事象と原因は同じ。
2段階認証をかけているアカウントなのになんで、Cloneも1回目のpushもできたんだろう?と不思議に思っていたら怒られた。

対応 : configファイルのurlに認証情報を追記する

設定を修正すればfetchもpullもpushもできるようになる

.git/config
:...省略...
[remote "origin"]
    url = https://{ユーザ名}:{トークン}@github.com/ponsuke/repository.git
:...省略...

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
102