git remote 命令用于管理与远程仓库的连接。它可以列出当前已配置的所有远程仓库、添加新的远程仓库,以及删除现有的远程仓库。
常见的 git remote 命令有以下几个:
- git remote: 列出当前所有已配置的远程仓库;
- git remote -v: 列出当前所有已配置的远程仓库及其对应的 URL;
- git remote add : 添加一个新的远程仓库,并指定一个名字和对应的 URL;
- git remote rm : 删除指定的远程仓库;
- git remote rename : 重命名指定的远程仓库。
示例:
1、列出当前所有已配置的远程仓库:
$ git remote
origin
2、列出当前所有已配置的远程仓库及其对应的 URL:
ruby
$ git remote -v
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
3、添加一个新的远程仓库:
$ git remote add upstream https://github.com/otheruser/repo.git
4、删除指定的远程仓库:
shell
$ git remote rm upstream
5、重命名指定的远程仓库:
$ git remote rename origin myorigin
注意: 参数一般为远程仓库的名字,通常是 origin,但这并不是必须的,你也可以起一个你自己喜欢的名字。 参数为远程仓库的 URL,可以是 HTTPS 或 SSH 协议的 URL。