| この記事の要点 |
|
このエラーの概要
git remote add origin を実行したときに出ます:
$ git remote add origin https://github.com/user/repo.git
fatal: remote origin already exists.
# 確認すると確かにある
$ git remote -v
origin https://github.com/old-user/old-repo.git (fetch)
origin https://github.com/old-user/old-repo.git (push)
git にとって 「リモート」は名前付きの参照です。origin という名前が既に使われていれば add は失敗します。これは安全機構で、知らずに別 URL に上書きされるのを防いでくれます。
解決パターン3つ
| やりたいこと | コマンド | 備考 |
|---|---|---|
| origin の URL を変えたいだけ | git remote set-url origin <new-url> | 最も安全。履歴・upstream 維持 |
| origin を消して付け直す | git remote remove origin → git remote add origin <url> | upstream 設定もリセットされる |
| 別名で並行追加 | git remote add upstream <url> | fork 元参照などで定番 |
対処A: set-url で URL だけ変更(推奨)
# 現在の origin URL を確認
git remote -v
git remote get-url origin
# URL を変更
git remote set-url origin https://github.com/new-user/new-repo.git
# SSH ↔ HTTPS 切替
git remote set-url origin git@github.com:user/repo.git
# fetch 用と push 用で別 URL にする (ミラーリング時)
git remote set-url --push origin git@gitlab.internal:user/repo.git
# 確認
git remote -v
# origin https://github.com/new-user/new-repo.git (fetch)
# origin https://github.com/new-user/new-repo.git (push)
# 試しに fetch
git fetch origin
対処B: 削除して付け直し
# remove (rm) でリモート削除
git remote remove origin
# あるいは古い書き方
git remote rm origin
# 確認(何も出ない)
git remote -v
# 改めて追加
git remote add origin https://github.com/user/repo.git
# 初回 push で upstream 設定
git push -u origin main
# upstream 設定だけ後から付けることもできる
git branch --set-upstream-to=origin/main main
対処C: 別名で追加(fork 開発で多用)
OSS の fork 開発では、自分の fork を origin、本家を upstream として両方扱います:
# 自分の fork
git remote add origin git@github.com:my-user/my-fork.git
# 本家を upstream として追加
git remote add upstream https://github.com/original-author/repo.git
git remote -v
# origin git@github.com:my-user/my-fork.git (fetch)
# origin git@github.com:my-user/my-fork.git (push)
# upstream https://github.com/original-author/repo.git (fetch)
# upstream https://github.com/original-author/repo.git (push)
# 本家の最新を取り込む
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
git clone 直後にこのエラーが出るのはなぜ?
git clone は自動的に origin を設定します。そのため clone 直後にもう一度 git remote add origin すると重複エラーになります。
git clone https://github.com/user/repo.git
cd repo
git remote -v
# origin https://github.com/user/repo.git (fetch) ← 既にある
# origin https://github.com/user/repo.git (push)
# ここで以下を実行するとエラー
git remote add origin https://github.com/user/repo.git
# fatal: remote origin already exists.
リモート一覧と詳細表示
# 一覧(URL 付き)
git remote -v
# 名前のみ
git remote
# 詳細
git remote show origin
# * remote origin
# Fetch URL: ...
# Push URL: ...
# HEAD branch: main
# Remote branches:
# main tracked
# Local branch configured for 'git pull':
# main merges with remote main
# Local ref configured for 'git push':
# main pushes to main (up to date)
# 名前変更(origin → upstream に rename したいとき)
git remote rename origin upstream
関連エラーと対処
| エラー | 状況 | 対処 |
|---|---|---|
error: No such remote: 'origin' | 削除済み or 未設定 | git remote add origin URL |
fatal: refusing to merge unrelated histories | 新規リモートに既存ローカルを push | git pull --allow-unrelated-histories origin main |
error: src refspec main does not match any | commit が一つも無い | git add . && git commit -m init |
! [rejected] main -> main (fetch first) | リモートに先行コミットあり | git pull --rebase 後 push |
FAQ
Q: set-url したのに古い URL に push されている
A: --push オプション付きで別 URL を設定した可能性。git remote -v で (fetch) と (push) を両方確認してください。
Q: リモートを丸ごとリセットしたい
A: .git/config を直接編集して [remote "origin"] セクションを削除する手もありますが、git remote remove origin の方が安全です。
Q: GitHub から GitLab に移行したい
A: git remote set-url origin git@gitlab.com:user/repo.git → git push --all + git push --tags で全ブランチとタグを移行できます。
子ページ
子ページはありません
同階層のページ
- fatal: remote origin already exists.
- fatal: '~' does not appear to be a git repository
- Cannot rebase: You have unstaged changes. Please commit or stash them.
- remote: error: denying non-fast-forward refs/heads/master (you should pull first)
- error: pathspec ... did not match any file(s) known to git.
- The following untracked working tree files would be overwritten by checkout
- fatal: Not a valid object name: 'master'.
- Unlink of file 'ファイル名' failed. Should I try again? (y/n)
- Another git process seems to be running in this repository
- error: Your local changes to the following files would be overwritten by checkout:
人気ページ
- 1 Eclipseで「サーバーに追加または除去できるリソースがありません。」の原因と対処法
- 2 tomcat の起動 / 停止ログと catalina.log・catalina.out の違い
- 3 JavaScript で base URL を取得する方法|window.location.origin
- 4 YouTube Data API v3 エラー一覧|403・400・404 の原因と対処
- 5 Laravel エラー一覧|500/Blade/DB 接続/ルーティングの代表エラー
- 6 3Dグラフィックスのソフト一覧|Blender・Metasequoiaと用途別の選び方
- 7 Spring Frameworkのアノテーション一覧
- 8 【Spring】@Valueアノテーションとは
- 9 CATALINA_HOME の確認方法 (Linux / Mac)
- 10 【Spring】@Autowiredアノテーションとは
最近更新/作成されたページ
- Visual Studio「デザイナーを表示できません」エラーの原因と対処 2026-10-28 12:06:00
- SSH 認証に失敗しました。再試行してください の対処 2026-10-28 12:06:00
- SSH2 秘密鍵の読み込みに失敗しました の原因と対処 2026-10-28 12:06:00
- TeraTerm のよくあるエラーと対処法完全ガイド — Connection refused / 2026-10-28 12:06:00
- Visual Studio エラー一覧|コンパイルエラー・警告の確認方法と対処 2026-10-28 11:39:57
- Whitelabel Error Page の原因と消し方|Spring Boot のエラーページ 2026-10-28 11:39:57
- Eclipseで「サーバーに追加または除去できるリソースがありません。」の原因と対処法 2026-10-28 11:39:57
- SQL WHERE 句完全ガイド 2026-10-28 11:39:57
- SQL JOIN 完全ガイド (INNER/LEFT/RIGHT/FULL OUTER) 2026-10-28 11:39:57
- tomcat の起動 / 停止ログと catalina.log・catalina.out の違い 2026-10-28 10:24:23
- Tomcat の起動確認方法 5 つ|localhost:8080・ポート・プロセス・ログ 2026-10-28 10:24:23
- Oracle 19c COMMITの使い方: 暗黙コミット・自動確定・応答不明時の確認 2026-10-28 09:59:09
- Oracle 19c DELETE文|削除対象の確認・COMMIT前の判断・ROLLBACKの条件 2026-10-28 09:59:09
- Oracle 19c INSERT文|INSERT ALL・SELECT・RETURNINGとMERGEの使い分け 2026-10-28 09:59:09
- Oracle 19cのトランザクション制御|COMMIT・ROLLBACK・分離レベルと接続設定 2026-10-28 09:59:09