Reinvent Yourself

技術メモや日々思っていることなど

gitでリモートリポジトリのパスを間違えてプッシュした時のエラー(ERROR: Repository not found.)を解決

はじめに

リモートリポジトリのパスを間違って設定してしまうと、プッシュ時に「ERROR: Repository not found.」エラーとなる。 この場合の対処方法をメモしておく。

エラー〜解決までの流れ(例:githubの場合)

プッシュ時にエラーとなる。

% git push -u origin master
ERROR: Repository not found.
Please make sure you have the correct access rights
and the repository exists.

「git remote add」のやり直しはできない

「git remote add」を正しい内容で行おうとするが「add」なので 既に追加したものは上書きされずにエラーとなる。

% git remote add origin git@github.com:xxxxxx/example.git
fatal: remote origin already exists.

「git remote set-url」で設定し直す

git remote set-url origin git@github.com:xxxxxx/example.git

プッシュが成功

% git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 232 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:xxxxxx/example.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

おまけ

「git remote -v」で設定内容を確認できる。

% git remote -v
origin  git@github.com/xxxxxx/example.git (fetch)
origin  git@github.com/xxxxxx/example.git (push)