首頁·終端機命令

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