git remote

管理远程仓库的连接,包括添加、删除、重命名和查看远程仓库

语法

git remote [<subcommand>] [<options>]

参数

参数说明示例级别
-v 显示远程仓库的 URL 详情 常用
add <name> <url> 添加新的远程仓库 常用
remove <name> 删除远程仓库 常用
rename <old> <new> 重命名远程仓库 常用
set-url <name> <url> 修改远程仓库的 URL 常用

示例

查看所有远程仓库及其 URL

git remote -v
origin https://github.com/user/repo.git (fetch) origin https://github.com/user/repo.git (push)

添加上游仓库(fork 场景常用)

git remote add upstream https://github.com/original/repo.git

删除远程仓库连接

git remote remove origin

将远程 URL 从 HTTPS 切换为 SSH

git remote set-url origin git@github.com:user/repo.git

查看远程仓库的详细信息

git remote show origin

技巧

相关命令