Setup and Config
Getting and Creating Projects
Basic Snapshotting
Branching and Merging
Sharing and Updating Projects
Inspection and Comparison
Patching
Debugging
External Systems
Server Admin
Guides
- gitattributes
- Command-line interface conventions
- Everyday Git
- Frequently Asked Questions (FAQ)
- Glossary
- Hooks
- gitignore
- gitmodules
- Revisions
- Submodules
- Tutorial
- Workflows
- All guides...
Administration
Plumbing Commands
- 2.37.1 → 2.44.0 no changes
- 2.37.0 06/27/22
- 2.36.1 → 2.36.6 no changes
- 2.36.0 04/18/22
- 2.35.1 → 2.35.8 no changes
- 2.35.0 01/24/22
- 2.30.1 → 2.34.8 no changes
- 2.30.0 12/27/20
- 2.29.1 → 2.29.3 no changes
- 2.29.0 10/19/20
概述
git remote [-v | --verbose] git remote add [-t <分支>] [-m <master>] [-f] [--[no-]tags] [--mirror=(fetch|push)] <名称> <URL> git remote rename [--[no-]progress] <旧名> <新名> git remote remove <名称> git remote set-head <名称> (-a | --auto | -d | --delete | <分支>) git remote set-branches [--add] <名称> <分支>… git remote get-url [--push] [--all] <名称> git remote set-url [--push] <名称> <新地址> [<旧地址>] git remote set-url --add [--push] <名称> <新地址> git remote set-url --delete [--push] <名称> <地址> git remote [-v | --verbose] show [-n] <名称>… git remote prune [-n | --dry-run] <名称>… git remote [-v | --verbose] update [-p | --prune] [(<组> | <远程仓库>)…]
命令
With no arguments, shows a list of existing remotes. Several subcommands are available to perform operations on the remotes.
- add
-
Add a remote named <name> for the repository at <URL>. The command
git fetch <name>
can then be used to create and update remote-tracking branches <name>/<branch>.使用
-f
选项,在设置远程信息之后立即运行git get <名称>
。使用
--tags
选项,git get <名称>
从远程仓库导入每个标记。使用
--no-tags
选项,git fetch <名称>
不会从远程仓库导入标签。默认情况下,只导入获取的分支上的标记(参见 git-fetch[1])。
With
-t <branch>
option, instead of the default glob refspec for the remote to track all branches under therefs/remotes/<name>/
namespace, a refspec to track only<branch>
is created. You can give more than one-t <branch>
to track multiple branches without grabbing all branches.使用
-m <master>
选项,可以设置一个符号引用/remotes/<名称>/HEAD
来指向远程仓库的<master>
分支。另请参见 set-head 命令。当用
--mirror=fetch
创建一个 fetch 镜像时, 引用不会被存储在 refs/remotes/ 命名空间中,而是远程的 refs/ 中的所有内容将直接被镜像到本地版本库的 refs/ 中。这个选项只有在裸库中才有意义,因为获取会覆盖任何本地提交。当用
--mirror=push
创建推送镜像时,git push
的行为就像传递--mirror
一样。 - rebase
-
将名为 < 旧名称 > 的远程重命名为 < 新名称 > 。所有远程跟踪的分支和远程的配置设置都被更新。
如果 <旧名称 >和< 新名称 >相同,并且< 旧名称 >是
$GIT_DIR/remotes
或$GIT_DIR/branches
下的文件,远程将被转换为配置文件格式。 - remove
- rm
-
删除名为 < 名称 > 的远程。该远程的所有远程跟踪分支和配置设置都被删除。
- set-head
-
设置或删除命名远程仓库的默认分支(即符号引用
refs/remotes/<名称>/HEAD
的目标)。不需要为远程仓库设置默认分支,但允许指定远程仓库的名称来代替特定分支。例如,如果origin
的默认分支设置为master
,则可以在通常指定origin/master
的任何位置指定origin
。设置
-d
或--delete
选项,符号引用refs/remotes/<名称>/HEAD
将被删除.使用
-a
或--auto
,查询远程仓库以确定其HEAD
,然后将符号引用refs/remotes/<名称>/HEAD
设置为同一分支。 例如,如果远程HEAD
指向`next`,git remote set-head origin -a`会将符号引用 `refs/remotes/origin/HEAD
设置为refs/remotes/origin/next
。这仅在refs/remotes/origin/next
已经存在时才有效;如果不是,则必须首先获取它。使用
<branch>
显式地设置符号引用refs/remotes/<名称>/HEAD
。例如,git remote set-head source master
会将这个符号引用 ` refs/remotes/source/HEAD`设置为ref/remotes/source/master
。这只有在refs/remote/source/master
已经存在的情况下才能工作;如果不存在,则必须首先获取它。 - set-branches
-
Changes the list of branches tracked by the named remote. This can be used to track a subset of the available remote branches after the initial setup for a remote.
被命名的分支将被解释为在
git remote add`命令中用 `-t
选项指定的。使用
--add
,不是替换当前跟踪分支列表,而是添加到该列表中。 - get-url
-
检索一个远程的 URLs。
insteadOf
和pushInsteadOf
的配置在此列出。默认情况下,只有第一个 URL 被列出。使用
--push
,查询的是推送的URLs,而不是获取的URLs。使用 `--all`选项,远程仓库的所有 URL 将被列出。
- set-url
-
改变远程的URLs。将远程 <名称> 的第一个匹配正则表达式 <旧url> 的URL(如果没有给出 <旧url>,则为第一个URL)设置为 <新url>。如果 <旧url> 不匹配任何URL,就会发生错误,并且什么都不会被改变。
使用
--push
,推送 URLs 被操作,而不是获取 URLs。使用
--add
,不改变现有的 URLs,而是添加新的 URL。With
--delete
, instead of changing existing URLs, all URLs matching regex <URL> are deleted for remote <name>. Trying to delete all non-push URLs is an error.Note that the push URL and the fetch URL, even though they can be set differently, must still refer to the same place. What you pushed to the push URL should be what you would see if you immediately fetched from the fetch URL. If you are trying to fetch from one place (e.g. your upstream) and push to another (e.g. your publishing repository), use two separate remotes.
- show
-
提供关于远程 <名称> 的一些信息。
使用
-n
选项,就不会先用git ls-remote <名称>
查询远程头指针,而是使用缓存的信息。 - prune
-
删除与 <名称> 相关的陈旧引用。默认情况下,<名称>下的陈旧远程跟踪分支会被删除,但根据全局配置和远程的配置,我们甚至可能修剪没有被推送到那里的本地标签。相当于
git fetch --prune <名称>
,只是不会取到新的引用。参见 git-fetch[1] 的剪枝部分,了解它将根据不同的配置修剪什么。
使用
--dry-run
选项,报告哪些分支将被修剪,但实际上不修剪它们。 - update
-
Fetch updates for remotes or remote groups in the repository as defined by
remotes.<group>
. If neither group nor remote is specified on the command line, the configuration parameter remotes.default will be used; if remotes.default is not defined, all remotes which do not have the configuration parameterremote.<name>.skipDefaultUpdate
set to true will be updated. (See git-config[1]).使用
--prune
选项,对所有被更新的远程进行修剪。
讨论
The remote configuration is achieved using the remote.origin.url
and remote.origin.fetch
configuration variables. (See 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] 文档