首页·终端命令

git remote

git

用法

git remote -v | git remote add <name> <url>

管理远端仓库的名字和地址;它只是记下来,在你真正 fetch 或 push 之前什么都不会传输。

常用选项

选项含义
-vlist the remotes with their URLs
add <name> <url>register another repository
set-url <name> <url>point an existing remote somewhere else
rename <old> <new>rename a remote
remove <name>forget a remote
show <name>branches it has and how they are tracked
prune <name>drop tracking refs for branches deleted there

示例

git remote -v

shows the fetch and push URL of every remote

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

adds the original repo alongside your fork

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

switches origin from HTTPS to ssh

难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. git remote 是做什么的?

管理远端仓库的名字和地址;它只是记下来,在你真正 fetch 或 push 之前什么都不会传输。

Q. 怎么写?

git remote -v | git remote add <name> <url> —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 7 个,完整列表在 man git。这条命令属于git。

相关命令

man 手册: man git-remote