MeWrite Docs

fatal: 'origin' does not appear to be a git repository

Gitでリモートリポジトリoriginが存在しない場合のエラー

概要

Gitでpush、pull、fetchなどのリモート操作を行う際、指定したリモートリポジトリ(通常は’origin’)が設定されていないか、URLが間違っている場合に発生するエラーです。

エラーメッセージ

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

原因

  1. リモートが未設定: git remote addを実行していない
  2. URLの間違い: リモートのURLが間違っている
  3. リポジトリが削除された: GitHub上でリポジトリが削除されている
  4. 名前の間違い: ‘origin’以外の名前でリモートを登録している
  5. 認証の問題: SSHキーやトークンの問題

解決策

1. リモートを追加

1
2
3
4
5
6
7
8
# リモートの確認
git remote -v

# 空の場合、リモートを追加
git remote add origin https://github.com/user/repo.git

# SSHの場合
git remote add origin git@github.com:user/repo.git

2. リモートURLを修正

1
2
3
4
5
6
7
8
9
# 現在のURLを確認
git remote -v

# URLを変更
git remote set-url origin https://github.com/user/correct-repo.git

# または削除して追加
git remote remove origin
git remote add origin https://github.com/user/correct-repo.git

3. リモート名を確認

1
2
3
4
5
6
7
8
# リモート一覧
git remote -v

# 'upstream' など別名で登録されている場合
git push upstream main

# originに名前変更
git remote rename upstream origin

4. リポジトリの存在確認

1
2
3
4
# GitHubでリポジトリが存在するか確認
# ブラウザで https://github.com/user/repo を開く

# 存在しない場合はGitHubで作成

5. SSH設定の確認

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# SSH接続テスト
ssh -T git@github.com

# SSHキーの確認
ls -la ~/.ssh/

# SSHキーを生成(必要な場合)
ssh-keygen -t ed25519 -C "your_email@example.com"

# GitHubにSSH公開鍵を登録
cat ~/.ssh/id_ed25519.pub

6. HTTPSとSSHの切り替え

1
2
3
4
5
# HTTPSからSSHに変更
git remote set-url origin git@github.com:user/repo.git

# SSHからHTTPSに変更
git remote set-url origin https://github.com/user/repo.git

7. クローンからやり直す

1
2
3
4
5
6
7
8
# 既存のディレクトリをバックアップ
mv my-project my-project-backup

# 正しいURLでクローン
git clone https://github.com/user/repo.git my-project

# ローカルの変更をコピー
cp -r my-project-backup/src my-project/

8. 認証情報の更新

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Credential Helperの確認
git config --global credential.helper

# macOS
git config --global credential.helper osxkeychain

# Windows
git config --global credential.helper manager-core

# キャッシュされた認証情報をクリア
git credential-cache exit

よくある間違い

  • git initのみでgit remote addをしていない
  • リポジトリURLのタイプミス(.gitの有無など)
  • プライベートリポジトリにアクセス権がない
  • SSHとHTTPSを混同している

関連エラー

参考リンク

Git の他のエラー

最終更新: 2025-12-13