LoginSignup
2
1

More than 1 year has passed since last update.

【Git】remote urlを変更する方法

Posted at

はじめに

GitLabからGitHubへリポジトリを移行する際にエラーになって調べたので、備忘録として残します。

前提条件

  • GitHubのアカウント作成&リポジトリは移行済み

エラー内容

  • 下記のコマンド実行後にエラーあり。(既にリモートは設定されていますと怒られている状況)
$ git remote add origin 移行先のURL

error: remote origin already exists.

方法

  • 既存のリモートURLの設定を確認する
$ git remote -v

> origin  git@gitLab.com:USERNAME/REPOSITORY.git (fetch)
> origin  git@gitLab.com:USERNAME/REPOSITORY.git (push)
  • 新しいリモートURLに変更する
$ git remote set-url origin 変更したいURL

  • 変更されているか確認する
$ git remote -v

> origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
> origin  git@github.com:USERNAME/REPOSITORY.git (push)

おまけ

  • HTTPSを使用するかSSHを使用するかで、git remote -vした時のURL表示が若干異なるので、注意してください。

  • HTTPS を使う場合

https://github.com/USERNAME/REPOSITORY.git
  • SSH を使う場合
git@github.com:USERNAME/REPOSITORY.git

参考記事

2
1
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
2
1