Git远程仓库地址操作命令

发布时间 2023-09-06 19:38:07作者: 小村村长

在Git中查看远程仓库地址,可以使用git remote命令。
git remote命令的基本用法如下:

git remote显示所有远程仓库的名称。默认是origin。
git remote -v显示所有远程仓库的名称和URL地址。
git remote add 添加一个新的远程仓库。
git remote rm 删除一个远程仓库。
git remote rename 重命名一个远程仓库。
git remote set-url 设置一个远程仓库的URL地址。
git remote show 查看某个远程仓库的详细信息。
git remote命令有很多用法,可以方便的管理多个远程仓库。

举几个例子:

显示所有远程仓库信息:

$ git remote -v
origin  https://github.com/jonny/repo.git (fetch) 
origin  https://github.com/jonny/repo.git (push)
$ git remote add upstream https://github.com/others/repo.git

删除远程仓库upstream:

$ git remote rm upstream

远端仓库改名:重命名origin为online:

$ git remote rename origin online

设置远程仓库online的URL地址:

$ git remote set-url online https://gitlab.com/jonny/repo.git

查看远程仓库online的详细信息:

$ git remote show online
* remote online
  Fetch URL: https://gitlab.com/jonny/repo.git
  Push  URL: https://gitlab.com/jonny/repo.git
  HEAD branch: master
  Remote branches:
    master                   tracked
    dev-feature              tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)