# git-remote
> 原文: [https://git-scm.com/docs/git-remote](https://git-scm.com/docs/git-remote)
## 名稱
git-remote - 管理一組跟蹤的存儲庫
## 概要
```
git remote [-v | --verbose]
git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
git remote rename <old> <new>
git remote remove <name>
git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
git remote set-branches [--add] <name> <branch>…?
git remote get-url [--push] [--all] <name>
git remote set-url [--push] <name> <newurl> [<oldurl>]
git remote set-url --add [--push] <name> <newurl>
git remote set-url --delete [--push] <name> <url>
git remote [-v | --verbose] show [-n] <name>…?
git remote prune [-n | --dry-run] <name>…?
git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)…?]
```
## 描述
管理您跟蹤其分支的存儲庫集(“遠程”)。
## OPTIONS
```
-v
```
```
--verbose
```
稍微冗長一點,并在名字后顯示遠程網址。注意:必須放在`remote`和`subcommand`之間。
## COMMANDS
沒有參數,顯示現有遙控器的列表。有幾個子命令可用于對遙控器執行操作。
```
add
```
添加名為< name>的遠程名稱對于< url>的存儲庫。然后,命令`git fetch <name>`可用于創建和更新遠程跟蹤分支< name> /< branch>。
使用`-f`選項,在設置遠程信息后立即運行`git fetch <name>`。
使用`--tags`選項,`git fetch <name>`從遠程存儲庫導入每個標記。
使用`--no-tags`選項,`git fetch <name>`不會從遠程存儲庫導入標記。
默認情況下,僅導入已獲取分支上的標記(請參閱 [git-fetch [1]](https://git-scm.com/docs/git-fetch) )。
使用`-t <branch>`選項,而不是默認的glob refspec用于遠程跟蹤`refs/remotes/<name>/`命名空間下的所有分支,而是創建僅跟蹤`<branch>`的refspec。您可以提供多個`-t <branch>`來跟蹤多個分支而不占用所有分支。
使用`-m <master>`選項,symbolic-ref `refs/remotes/<name>/HEAD`被設置為指向遠程的`<master>`分支。另請參見set-head命令。
使用`--mirror=fetch`創建獲取鏡像時,refs不會存儲在 _refs / remotes /_ 命名空間中,而是遙控器上 _refs /_ 中的所有內容都將被直接鏡像進入本地存儲庫中的 _refs /_ 。此選項僅在裸存儲庫中有意義,因為獲取將覆蓋任何本地提交。
使用`--mirror=push`創建推鏡時,`git push`將始終表現為`--mirror`通過。
```
rename
```
重命名名為< old>的遠程名稱到< new>。將更新遠程的所有遠程跟蹤分支和配置設置。
如果< old>和< new>是相同的,< old>是`$GIT_DIR/remotes`或`$GIT_DIR/branches`下的文件,遠程轉換為配置文件格式。
```
remove
```
```
rm
```
刪除名為< name>的遠程數據庫。將刪除遠程的所有遠程跟蹤分支和配置設置。
```
set-head
```
設置或刪除指定遠程的默認分支(即symbolic-ref `refs/remotes/<name>/HEAD`的目標)。不需要具有遠程的默認分支,但允許指定遠程的名稱來代替特定分支。例如,如果`origin`的默認分支設置為`master`,則可以在通常指定`origin/master`的任何位置指定`origin`。
使用`-d`或`--delete`,刪除符號ref `refs/remotes/<name>/HEAD`。
使用`-a`或`--auto`,查詢遠程以確定其`HEAD`,然后將symbolic-ref `refs/remotes/<name>/HEAD`設置為同一分支。例如,如果遠程`HEAD`指向`next`,“`git remote set-head origin -a`”將symbolic-ref `refs/remotes/origin/HEAD`設置為`refs/remotes/origin/next`。這僅在`refs/remotes/origin/next`已存在時才有效;如果不是,它必須先取出。
使用`<branch>`顯式設置symbolic-ref `refs/remotes/<name>/HEAD`。例如,“git remote set-head origin master”將symbolic-ref `refs/remotes/origin/HEAD`設置為`refs/remotes/origin/master`。這僅在`refs/remotes/origin/master`已存在時才有效;如果不是,它必須先取出。
```
set-branches
```
更改命名遠程跟蹤的分支列表。在初始設置遙控器之后,這可用于跟蹤可用遠程分支的子集。
命名分支將被解釋為使用 _git remote add_ 命令行上的`-t`選項指定。
使用`--add`,而不是替換當前跟蹤的分支列表,添加到該列表。
```
get-url
```
檢索遠程的URL。這里擴展了`insteadOf`和`pushInsteadOf`的配置。默認情況下,僅列出第一個URL。
使用`--push`,將查詢推送URL而不是提取URL。
使用`--all`,將列出遠程的所有URL。
```
set-url
```
更改遠程的URL。設置遠程< name>的第一個網址匹配正則表達式< oldurl> (如果沒有給出< oldurl>則是第一個URL)到< newurl>。如果< oldurl>與任何URL都不匹配,發生錯誤并且沒有任何更改。
使用`--push`,操縱推送URL而不是獲取URL。
使用`--add`,不添加現有URL,而是添加新URL。
使用`--delete`,而不是更改現有網址,所有匹配正則表達式< url>的網址已刪除遠程< name>。嘗試刪除所有非推送URL是一個錯誤。
請注意,推送URL和提取URL即使可以設置不同,仍必須引用相同的位置。您推送到推送URL的內容應該是您從提取URL中立即獲取的內容。如果您嘗試從一個位置(例如您的上游)獲取并推送到另一個位置(例如您的發布存儲庫),請使用兩個單獨的遙控器。
```
show
```
提供有關遠程< name>的一些信息。
使用`-n`選項,不會先使用`git ls-remote <name>`查詢遠程磁頭;而是使用緩存的信息。
```
prune
```
刪除與< name>關聯的陳舊引用。默認情況下,< name>下的過時遠程跟蹤分支被刪除,但根據全局配置和遠程配置,我們甚至可以修剪那些尚未推送的本地標簽。相當于`git fetch --prune <name>`,但不會獲取新的引用。
請參閱 [git-fetch [1]](https://git-scm.com/docs/git-fetch) 的PRUNING部分,了解它將根據各種配置進行修剪的內容。
使用`--dry-run`選項,報告將修剪哪些分支,但不實際修剪它們。
```
update
```
獲取由遠程數據庫定義的存儲庫中的遠程數據庫或遠程組的更新。< group>。如果在命令行中既未指定group也未指定remote,則將使用配置參數remotes.default;如果未定義remotes.default,則所有沒有配置參數remote的遙控器將被更新。< name> .skipDefaultUpdate設置為true。 (參見 [git-config [1]](https://git-scm.com/docs/git-config) )。
使用`--prune`選項,對所有已更新的遙控器運行修剪。
## 討論
使用`remote.origin.url`和`remote.origin.fetch`配置變量實現遠程配置。 (參見 [git-config [1]](https://git-scm.com/docs/git-config) )。
## 例子
* 添加一個新的遠程,獲取,并從中檢出一個分支
```
$ git remote
origin
$ git branch -r
origin/HEAD -> origin/master
origin/master
$ git remote add staging git://git.kernel.org/.../gregkh/staging.git
$ git remote
origin
staging
$ git fetch staging
...
From git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
* [new branch] master -> staging/master
* [new branch] staging-linus -> staging/staging-linus
* [new branch] staging-next -> staging/staging-next
$ git branch -r
origin/HEAD -> origin/master
origin/master
staging/master
staging/staging-linus
staging/staging-next
$ git checkout -b staging staging/master
...
```
* 模仿 _git clone_ 但僅跟蹤選定的分支
```
$ mkdir project.git
$ cd project.git
$ git init
$ git remote add -f -t master -m master origin git://example.com/git.git/
$ git merge origin
```
## 也可以看看
[git-fetch [1]](https://git-scm.com/docs/git-fetch) [git-branch [1]](https://git-scm.com/docs/git-branch) [git-config [1]](https://git-scm.com/docs/git-config)
## GIT
部分 [git [1]](https://git-scm.com/docs/git) 套件
- git
- git-config
- git-help
- git-init
- git-clone
- git-add
- git-status
- git-diff
- git-commit
- git-reset
- git-rm
- git-mv
- git-branch
- git-checkout
- git-merge
- git-mergetool
- git-log
- git-stash
- git-tag
- git-worktree
- git-fetch
- git-pull
- git-push
- git-remote
- git-submodule
- git-show
- git-log
- git-shortlog
- git-describe
- git-apply
- git-cherry-pick
- git-rebase
- git-revert
- git-bisect
- git-blame
- git-grep
- gitattributes
- giteveryday
- gitglossary
- githooks
- gitignore
- gitmodules
- gitrevisions
- gittutorial
- gitworkflows
- git-am
- git-format-patch
- git-send-email
- git-request-pull
- git-svn
- git-fast-import
- git-clean
- git-gc
- git-fsck
- git-reflog
- git-filter-branch
- git-instaweb
- git-archive
- git-bundle
- git-daemon
- git-update-server-info
- git-cat-file
- git-check-ignore
- git-checkout-index
- git-commit-tree
- git-count-objects
- git-diff-index
- git-for-each-ref
- git-hash-object
- git-ls-files
- git-merge-base
- git-read-tree
- git-rev-list
- git-rev-parse
- git-show-ref
- git-symbolic-ref
- git-update-index
- git-update-ref
- git-verify-pack
- git-write-tree