Git Changing a remote’s URL

ใช้สำหรับเปลี่ยน remote-url ในกรณีที่เรา clone มาแล้ว แต่เกิิด repo บน github ถูกเปลี่ยน แต่บน local ไม่ได้เปลี่ยนตาม ให้เรา set remote url ใหม่ดังนี้ ซึ่งกรณีที่จะเปลี่ยนจาก SSH ไปใช้ https ก็ทำเช่นเดียวกัน

1. Open Git Bash / Windows Terminal

2. Change the current working directory to your local project.

3. List your existing remotes in order to get the name of the remote you want to change.

git remote -v
origin  https://hostname/OLD_USERNAME/OLD_REPOSITORY.git (fetch)
origin  https://hostname/OLD_USERNAME/OLD_REPOSITORY.git (push)

4. Change your remote’s URL from HTTPS to SSH with the git remote set-url command.

git remote set-url origin https://hostname/NEW_USERNAME/NEW_REPOSITORY.git

5. Verify that the remote URL has changed.

git remote -v
# Verify new remote URL
origin  https://hostname/NEW_USERNAME/NEW_REPOSITORY.git (fetch)
origin  https://hostname/NEW_USERNAME/NEW_REPOSITORY.git (push)

Ref: https://help.github.jp/enterprise/2.11/user/articles/changing-a-remote-s-url/