git remote set-url
命令可以改变一个代码库的url.
git remote set-url
命令可以接受两个参数:
The git remote set-url command takes two arguments:
- 一个远程名字,比如:
origin
- 远程的url,比如
https://github.com/USERNAME/REPOSITORY_2.git
如果你想改为使用 HTTPSgit@github.com:USER/REPOSITORY_2.git
如果你想改为使用SSH
远端url从ssh改成https
- 打开终端 (Mac 和 Linux) 或者命令行 (Windows).
- cd到你的目录里.
- 显示现在的远程url.
git remote -v origin git@github.com:USERNAME/REPOSITORY.git (fetch) origin git@github.com:USERNAME/REPOSITORY.git (push)
- 使用
remote set-url
命令切换url.git remote set-url origin https://github.com/USERNAME/REPOSITORY_2.git
- 验证一下是不是已经改变.
git remote -v origin https://github.com/USERNAME/REPOSITORY2.git (fetch) origin https://github.com/USERNAME/REPOSITORY2.git (push)
下一次你使用
git fetch
,git pull
, 或者git push
命令的时候,会提示你输入用户名和密码。
Switching remote URLs from HTTPS to SSH
- 打开终端 (Mac 和 Linux) 或者命令行 (Windows).
- cd到你的目录里.
-
显示现在的远程url.
git remote -v origin https://github.com/USERNAME/REPOSITORY.git (fetch) origin https://github.com/USERNAME/REPOSITORY.git (push)
- 使用
remote set-url
命令切换url.git remote set-url origin git@github.com:USERNAME/REPOSITORY2.git
- 验证一下是不是已经改变.
git remote -v origin git@github.com:USERNAME/REPOSITORY2.git (fetch) origin git@github.com:USERNAME/REPOSITORY2.git (push)