设置和配置
获取和创建项目
基本快照
分支与合并
共享和更新项目
检查和比较
打补丁
调试
电子邮件
外部系统
服务器管理
指南
管理
底层命令
- 2.45.1 → 2.52.0 无更改
-
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> 的远程。然后可以使用
gitfetch<name> 命令来创建和更新远程跟踪分支 <name>/<branch>。使用
-f选项时,在设置完远程信息后立即运行gitfetch<name>。使用
--tags选项时,gitfetch<name> 会从远程仓库导入所有标签。使用
--no-tags选项时,gitfetch<name> 不会从远程仓库导入标签。默认情况下,仅导入已获取分支上的标签(请参阅 git-fetch[1])。
使用
-t<branch> 选项,而不是默认的 glob refspec 来跟踪refs/remotes/<name>/命名空间下的所有分支,而是创建一个仅跟踪 <branch> 的 refspec。你可以给出多个-t<branch> 来跟踪多个分支,而无需获取所有分支。使用
-m<master> 选项,将设置一个符号引用refs/remotes/<name>/HEAD来指向远程的 <master> 分支。另请参阅 set-head 命令。当使用
--mirror=fetch创建一个 fetch mirror 时,引用不会存储在 refs/remotes/ 命名空间中,而是远程的 refs/ 下的任何内容都会直接镜像到本地仓库的 refs/ 中。此选项仅在裸仓库中有意义,因为 fetch 会覆盖任何本地提交。当使用
--mirror=push创建一个 push mirror 时,gitpush将始终表现得好像传递了--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,那么gitremoteset-headorigin-a将把符号引用refs/remotes/origin/HEAD设置为refs/remotes/origin/next。只有当refs/remotes/origin/next已存在时,此操作才有效;否则,必须先进行 fetch。使用 <branch> 显式设置符号引用
refs/remotes/<name>/HEAD。例如,gitremoteset-headoriginmaster将把符号引用refs/remotes/origin/HEAD设置为refs/remotes/origin/master。只有当refs/remotes/origin/master已存在时,此操作才有效;否则,必须先进行 fetch。 - set-branches
-
更改指定远程跟踪的分支列表。这可用于在远程初始设置后跟踪远程可用分支的子集。
指定的受跟踪分支将按照在
gitremoteadd命令行的-t选项中所指定的方式进行解释。使用
--add时,不是替换当前跟踪的分支列表,而是将新分支添加到该列表中。 - get-url
-
检索远程的 URL。在此会展开
insteadOf和pushInsteadOf的配置。默认情况下,仅列出第一个 URL。使用
--push时,查询的是 push URL 而不是 fetch URL。使用
--all时,将列出远程的所有 URL。 - set-url
-
更改远程的 URL。将远程 <name> 中第一个匹配正则表达式 <oldurl> 的 URL(如果未给出 <oldurl>,则为第一个 URL)更改为 <newurl>。如果 <oldurl> 不匹配任何 URL,则会发生错误且不进行任何更改。
使用
--push时,将操作 push URL 而不是 fetch URL。使用
--add时,不是更改现有 URL,而是添加新 URL。使用
--delete时,不是更改现有 URL,而是删除远程 <name> 中所有匹配正则表达式 <URL> 的 URL。尝试删除所有非 push URL 会导致错误。请注意,push URL 和 fetch URL 尽管可以设置不同,但它们仍然必须指向同一个地方。你推送到 push URL 的内容应该与你在立即从 fetch URL 获取时看到的内容一致。如果你试图从一个地方(例如你的上游)获取,然后推送到另一个地方(例如你的发布仓库),请使用两个独立的远程。
- show
-
提供关于远程 <name> 的一些信息。
使用
-n选项时,不会先使用gitls-remote<name> 查询远程 HEAD;而是使用缓存的信息。 - prune
-
删除与 <name> 相关的陈旧引用。默认情况下,会删除 <name> 下的陈旧远程跟踪分支,但根据全局配置和远程的配置,我们甚至可能会修剪未推送到那里的本地标签。相当于
gitfetch--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