全部学科
Python全栈
python
NodeJS全栈
nodejs
小程序首页
📅 2026-05-11 6 分钟 ✍️ juanwangdev

git remote 管理远程仓库

git remote 命令用于查看、添加、修改、删除远程仓库的连接。

基本用法

Bash
# 查看所有远程仓库
git remote

# 查看远程仓库详情
git remote -v

# 添加远程仓库
git remote add <name> <url>

# 删除远程仓库
git remote remove <name>

查看远程仓库

Bash
# 列出远程仓库名
$ git remote
origin

# 详细显示(含 URL)
$ git remote -v
origin  https://github.com/user/repo.git (fetch)
origin  https://github.com/user/repo.git (push)

添加远程仓库

Bash
# 添加名为 origin 的远程仓库
git remote add origin https://github.com/user/repo.git

# 添加多个远程仓库
git remote add upstream https://github.com/original/repo.git
git remote add backup https://backup.server/repo.git

# 查看结果
$ git remote -v
origin   https://github.com/user/repo.git (fetch)
origin   https://github.com/user/repo.git (push)
upstream https://github.com/original/repo.git (fetch)
upstream https://github.com/original/repo.git (push)

修改远程仓库

Bash
# 重命名远程仓库
git remote rename <old-name> <new-name>
git remote rename origin github

# 修改远程仓库 URL
git remote set-url <name> <new-url>
git remote set-url origin https://new.url/repo.git

# 修改推送 URL(与拉取不同)
git remote set-url --push <name> <push-url>

删除远程仓库

Bash
# 删除远程仓库连接
git remote remove <name>
git remote remove backup

# 或使用 rm(简写)
git remote rm backup

查看远程仓库信息

Bash
# 查看详细信息
git remote show origin

# 输出示例
* remote origin
  Fetch URL: https://github.com/user/repo.git
  Push  URL: https://github.com/user/repo.git
  HEAD branch: main
  Remote branches:
    main tracked
    dev  tracked
  Local branches configured for 'git pull':
    main merges with remote main
  Local refs configured for 'git push':
    main pushes to main

远程仓库名称约定

名称用途
origin克隆时的默认远程仓库
upstream原始仓库(fork 场景)
backup备份仓库

克隆仓库时自动创建 origin 远程连接,无需手动添加。

要点总结

  1. git remote -v 查看远程仓库详情
  2. git remote add <name> <url> 添加远程仓库
  3. git remote set-url 修改 URL
  4. git remote remove <name> 删除远程仓库
  5. origin 是默认远程仓库名称

📝 发现内容有误?点击此处直接编辑

← 上一篇 git push 推送更改
下一篇 → 远程分支跟踪
想查看更多题目和详细解析?
小程序提供完整的题库、模拟考试和详细解析
马上就来

长按或扫描二维码,立即体验

扫码体验小程序
马上就来
使用微信扫描二维码
立即体验完整题库