设置和配置
获取和创建项目
基本快照
分支与合并
共享和更新项目
检查和比较
打补丁
调试
电子邮件
外部系统
服务器管理
指南
管理
底层命令
- 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