1、作用:
用于用于管理 Git 仓库中的远程仓库,提供了一些用于查看、添加、重命名和删除远程仓库的功能
2、常见用法:
git remote
:列出当前仓库中已配置的远程仓库。git remote -v
:列出当前仓库中已配置的远程仓库,并显示它们的 URL。git remote add <remote_name> <remote_url>
:添加一个新的远程仓库。指定一个远程仓库的名称和 URL,将其添加到当前仓库中。git remote rename <old_name> <new_name>
:将已配置的远程仓库重命名。git remote remove <remote_name>
:从当前仓库中删除指定的远程仓库。git remote set-url <remote_name> <new_url>
:修改指定远程仓库的 URL。git remote show <remote_name>
:显示指定远程仓库的详细信息,包括 URL 和跟踪分支。
下列出了远程仓库、添加远程仓库、重命名远程仓库、删除远程仓库、修改远程仓库 URL 和查看远程仓库信息的用法
git remote
git remote -v
git remote add origin git@gitee.com:knifecf/c_-study.git
git remote rename origin new-origin
git remote remove new-origin
git remote set-url origin git@gitee.com:knifecf/c_-study.git
git remote show origin
3、应用实例:
1)列出了远程仓库
Administrator@FAN MINGW64 /e/debug/C语言 (main)
$ git remote
origin
Administrator@FAN MINGW64 /e/debug/C语言 (main)
$ git remote -v
origin git@gitee.com:knifecf/c_-study.git (fetch)
origin git@gitee.com:knifecf/c_-study.git (push)
2)添加远程仓库
Administrator@FAN MINGW64 /e/debug/C语言 (main)
$ git remote add hack git@gitee.com:knifecf/c_-study.git
3)重命名远程仓库
Administrator@FAN MINGW64 /e/debug/C语言 (main)
$ git remote rename hack origin
4)删除远程仓库
Administrator@FAN MINGW64 /e/debug/C语言 (main)
$ git remote remove origin
5)修改指定远程仓库的 URL
Administrator@FAN MINGW64 /e/debug/C语言 (main)
$ git remote set-url origin https://gitee.com/knifecf/c_-study.git
6)显示指定远程仓库的详细信息
Administrator@FAN MINGW64 /e/debug/C语言 (main)
$ git remote show origin
* remote origin
Fetch URL: git@gitee.com:knifecf/c_-study.git
Push URL: git@gitee.com:knifecf/c_-study.git
HEAD branch: master
Remote branches:
main new (next fetch will store in remotes/origin)
master new (next fetch will store in remotes/origin)
Local ref configured for 'git push':
main pushes to main (up to date)