設定和配置
獲取和建立專案
基本快照
分支與合併
共享和更新專案
檢查和比較
打補丁
除錯
電子郵件
外部系統
伺服器管理
指南
管理
底層命令
- 2.45.1 → 2.50.1 無更改
-
2.45.0
2024-04-29
- 2.37.1 → 2.44.4 無更改
-
2.37.0
2022-06-27
- 2.36.1 → 2.36.6 無更改
-
2.36.0
2022-04-18
- 2.35.1 → 2.35.8 無更改
-
2.35.0
2022-01-24
- 2.30.1 → 2.34.8 無更改
-
2.30.0
2020-12-27
- 2.29.1 → 2.29.3 無更改
-
2.29.0
2020-10-19
- 2.23.1 → 2.28.1 無更改
-
2.23.0
2019-08-16
- 2.18.1 → 2.22.5 無更改
-
2.18.0
2018-06-21
- 2.17.1 → 2.17.6 無更改
-
2.17.0
2018-04-02
- 2.10.5 → 2.16.6 無更改
-
2.9.5
2017-07-30
- 2.8.6 無更改
-
2.7.6
2017-07-30
-
2.6.7
2017-05-05
- 2.4.12 → 2.5.6 無更改
-
2.3.10
2015-09-28
- 2.1.4 → 2.2.3 無更改
-
2.0.5
2014-12-17
概要
git remote [-v | --verbose] git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=(fetch|push)] <name> <URL> git remote rename [--[no-]progress] <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>)…]
命令
不帶引數時,顯示現有遠端倉庫列表。有幾個子命令可用於對遠端倉庫執行操作。
- add
-
為 <URL> 處的倉庫新增一個名為 <name> 的遠端倉庫。然後可以使用命令
git
fetch
<name> 來建立和更新遠端跟蹤分支 <name>/<branch>。使用
-f
選項,git
fetch
<name> 在設定遠端資訊後立即執行。使用
--tags
選項,git
fetch
<name> 從遠端倉庫匯入所有標籤。使用
--no-tags
選項,git
fetch
<name> 不從遠端倉庫匯入標籤。預設情況下,只匯入已獲取分支上的標籤(參見 git-fetch[1])。
使用
-t
<branch> 選項,不是為遠端倉庫跟蹤refs/remotes/
<name>/
名稱空間下的所有分支建立預設的全域性引用規範,而是建立一個僅跟蹤 <branch> 的引用規範。你可以指定多個-t
<branch> 以跟蹤多個分支而無需獲取所有分支。使用
-m
<master> 選項,設定符號引用refs/remotes/
<name>/HEAD
以指向遠端的 <master> 分支。另請參閱 set-head 命令。當使用
--mirror=fetch
建立抓取映象時,引用不會儲存在 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
-
設定或刪除指定遠端倉庫的預設分支(即符號引用
refs/remotes/
<name>/HEAD
的目標)。遠端倉庫不要求有預設分支,但設定預設分支允許在需要指定特定分支的地方直接使用遠端倉庫的名稱。例如,如果origin
的預設分支設定為master
,那麼在任何通常需要指定origin/master
的地方都可以指定origin
。使用
-d
或--delete
選項,符號引用refs/remotes/
<name>/HEAD
將被刪除。使用
-a
或--auto
選項,將查詢遠端倉庫以確定其HEAD
,然後將符號引用refs/remotes/
<name>/HEAD
設定為相同的分支。例如,如果遠端HEAD
指向next
,則git
remote
set-head
origin
-a
將把符號引用refs/remotes/origin/HEAD
設定為refs/remotes/origin/next
。這僅在refs/remotes/origin/next
已經存在的情況下有效;如果不存在,則必須先獲取。使用 <branch> 來顯式設定符號引用
refs/remotes/
<name>/HEAD
。例如,git
remote
set-head
origin
master
將把符號引用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> 的 URL(如果未給出 <oldurl>,則為第一個 URL)設定為 <newurl>。如果 <oldurl> 不匹配任何 URL,則會發生錯誤且不進行任何更改。
使用
--push
選項,操作的是推送 URL 而不是抓取 URL。使用
--add
選項,不是更改現有 URL,而是新增新的 URL。使用
--delete
選項,不是更改現有 URL,而是刪除遠端倉庫 <name> 中所有匹配正則表示式 <URL> 的 URL。嘗試刪除所有非推送 URL 會導致錯誤。請注意,推送 URL 和抓取 URL 即使可以設定不同,也必須指向同一個位置。你推送到推送 URL 的內容,應該與你立即從抓取 URL 獲取時看到的內容一致。如果你嘗試從一個地方(例如你的上游倉庫)抓取,並推送到另一個地方(例如你的釋出倉庫),請使用兩個獨立的遠端倉庫。
- show
-
顯示有關遠端倉庫 <name> 的一些資訊。
使用
-n
選項,不會首先透過git
ls-remote
<name> 查詢遠端 HEAD;而是使用快取資訊。 - prune
-
刪除與 <name> 相關的過時引用。預設情況下,<name> 下的過時遠端跟蹤分支將被刪除,但根據全域性配置和遠端配置,我們甚至可能修剪未推送到該遠端倉庫的本地標籤。等同於
git
fetch
--prune
<name>,但不會獲取新的引用。有關根據各種配置進行修剪的詳細資訊,請參閱 git-fetch[1] 的 PRUNING(修剪)部分。
使用
--dry-run
選項,報告將修剪哪些分支,但實際上不進行修剪。 - update
-
按照
remotes.
<group> 的定義,在倉庫中獲取遠端倉庫或遠端組的更新。如果命令列上未指定組或遠端倉庫,將使用配置引數 remotes.default;如果 remotes.default 未定義,則所有未將配置引數remote.
<name>.skipDefaultUpdate
設定為 true 的遠端倉庫都將更新。(參見 git-config[1])。使用
--prune
選項,對所有更新的遠端倉庫執行修剪操作。
討論
遠端配置透過使用 remote.origin.url
和 remote.origin.fetch
配置變數實現。(參見 git-config[1])。
退出狀態
成功時,退出狀態為 0
。
當諸如 add、rename 和 remove 等子命令找不到相關遠端倉庫時,退出狀態為 2
。當遠端倉庫已存在時,退出狀態為 3
。
發生任何其他錯誤時,退出狀態可能是任何其他非零值。
示例
-
新增新遠端倉庫,抓取,並從中檢出一個分支
$ 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 switch -c 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