設定與組態
取得與建立專案
基本快照
分支與合併
分享與更新專案
檢查與比較
修補
除錯
電子郵件
外部系統
伺服器管理
指南
管理
底層命令
- 2.45.1 → 2.47.0 無變更
-
2.45.0
04/29/24
- 2.37.1 → 2.44.2 無變更
-
2.37.0
06/27/22
- 2.36.1 → 2.36.6 無變更
-
2.36.0
04/18/22
- 2.35.1 → 2.35.8 無變更
-
2.35.0
01/24/22
- 2.30.1 → 2.34.8 無變更
-
2.30.0
12/27/20
- 2.29.1 → 2.29.3 無變更
-
2.29.0
10/19/20
- 2.23.1 → 2.28.1 無變更
-
2.23.0
08/16/19
- 2.18.1 → 2.22.5 無變更
-
2.18.0
06/21/18
- 2.17.1 → 2.17.6 無變更
-
2.17.0
04/02/18
- 2.10.5 → 2.16.6 無變更
-
2.9.5
07/30/17
- 2.8.6 無變更
-
2.7.6
07/30/17
-
2.6.7
05/05/17
- 2.4.12 → 2.5.6 無變更
-
2.3.10
09/28/15
- 2.1.4 → 2.2.3 無變更
-
2.0.5
12/17/14
概要
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>
選項時,會建立一個 refspec 來追蹤僅<branch>
,而不是用於追蹤refs/remotes/<name>/
命名空間下所有分支的預設 glob refspec。您可以提供多個-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。將與正規表示式 <oldurl> 匹配(如果未給定 <oldurl> 則為第一個 URL)的遠端 <name> 的第一個 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>
查詢遠端標頭;而是使用快取資訊。 - prune
-
刪除與 <name> 關聯的過時引用。預設情況下,會刪除 <name> 下的過時遠端追蹤分支,但根據全域組態和遠端的組態,我們甚至可能會修剪未推送到該處的本機標籤。相當於
git fetch --prune <name>
,但不會提取任何新的引用。請參閱 git-fetch[1] 的「修剪」章節,以了解根據各種組態會修剪哪些內容。
使用
--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
GIT
屬於 git[1] 套件的一部分