リモートの URL の変更
「git remote set-url」コマンドにより、既存のリモートリポジトリ URL を変更できます。
ここには以下の内容があります:
参考: HTTPS と SSH URL との違いについては、「どのリモート URL を使うべきか?」を参照してください。
git remote set-urlコマンドは 2 つの引数を取ります:
- 既存のリモート名。 
originやupstreamがよく使われます。 - 
リモートの新しい URL。 例:
- 
HTTPS を使うよう更新する場合、URL は以下のようになります:
https://[hostname]/USERNAME/REPOSITORY.git - 
SSH を使うよう更新する場合、URL は以下のようになります:
git@hostname:USERNAME/REPOSITORY.git 
 - 
 
リモート URL の SSH から HTTPS への切り替え
- 
ターミナルターミナルGit Bashを開いてください。
 - 
ワーキングディレクトリをローカルプロジェクトに変更します。
 - 
変更したいリモートの名前を取得するため、既存のリモート一覧を表示します。
$ git remote -v > origin git@hostname:USERNAME/REPOSITORY.git (fetch) > origin git@hostname:USERNAME/REPOSITORY.git (push) - 
Change your remote's URL from SSH to HTTPS with the
git remote set-urlcommand.$ git remote set-url origin https://hostname/USERNAME/REPOSITORY.git - 
リモート URL が変更されたことを検証します。
$ git remote -v # Verify new remote URL > origin https://hostname/USERNAME/REPOSITORY.git (fetch) > origin https://hostname/USERNAME/REPOSITORY.git (push) 
The next time you git fetch, git pull, or git push to the remote repository, you'll be asked for your GitHub username and password.
- If you have two-factor authentication enabled, you must create a personal access token to use instead of your GitHub password.
 - Git が GitHub と通信するたびに GitHub のユーザ名とパスワードを思い出すよう、認証情報ヘルパーを使用することができます。
 
リモート URL を HTTPS から SSH に切り替える
- 
ターミナルターミナルGit Bashを開いてください。
 - 
ワーキングディレクトリをローカルプロジェクトに変更します。
 - 
変更したいリモートの名前を取得するため、既存のリモート一覧を表示します。
$ git remote -v > origin https://hostname/USERNAME/REPOSITORY.git (fetch) > origin https://hostname/USERNAME/REPOSITORY.git (push) - 
Change your remote's URL from HTTPS to SSH with the
git remote set-urlcommand.$ git remote set-url origin git@hostname:USERNAME/REPOSITORY.git - 
リモート URL が変更されたことを検証します。
$ git remote -v # Verify new remote URL > origin git@hostname:USERNAME/REPOSITORY.git (fetch) > origin git@hostname:USERNAME/REPOSITORY.git (push) 
トラブルシューティング
You may encounter these errors when trying to change a remote.
No such remote '[name]'
This error means that the remote you tried to change doesn't exist:
$ git remote set-url sofake https://hostname/octocat/Spoon-Knife
> fatal: No such remote 'sofake'
リモート名を正しく入力したか確認してください。