Skip to content

git-remote

管理跟踪的仓库集合。

概要

bash
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>)...]

描述

管理您跟踪其分支的仓库("远程")集合。

选项

  • -v, --verbose:稍微更详细,在名称后显示远程 URL。对于 promisor 远程,还显示配置了哪些过滤器。注意:必须放在 remote 和子命令之间。

命令

不带参数时,显示现有远程的列表。有几个子命令可用于对远程执行操作。

  • add:添加一个名为 <name> 的远程仓库。然后可以使用 git fetch <name> 命令创建和更新远程跟踪分支 <name>/<branch>

    • 使用 -f 选项,设置远程信息后立即运行 git fetch <name>
    • 使用 --tags 选项,git fetch <name> 从远程仓库导入每个标签。
    • 使用 --no-tags 选项,git fetch <name> 不从远程仓库导入标签。
    • 使用 -t <branch> 选项,创建仅跟踪 <branch> 的 refspec。
    • 使用 -m <master> 选项,设置符号引用 refs/remotes/<name>/HEAD 指向远程的 <master> 分支。
  • rename:将名为 <old> 的远程重命名为 <new>。所有远程跟踪分支和配置设置都将更新。

  • remove, rm:删除名为 <name> 的远程。所有远程跟踪分支和配置设置都将被删除。

  • set-head:设置或删除命名远程的默认分支。

    • 使用 -d--delete,删除符号引用 refs/remotes/<name>/HEAD
    • 使用 -a--auto,查询远程以确定其 HEAD
  • set-branches:更改命名远程跟踪的分支列表。

    • 使用 --add,添加到当前跟踪的分支列表中。
  • get-url:检索远程的 URL。

    • 使用 --push,查询推送 URL 而不是获取 URL。
    • 使用 --all,列出远程的所有 URL。
  • set-url:更改远程的 URL。

    • 使用 --push,操作推送 URL 而不是获取 URL。
    • 使用 --add,添加新 URL 而不是更改现有 URL。
    • 使用 --delete,删除匹配正则表达式的 URL。
  • show:显示有关远程 <name> 的一些信息。

    • 使用 -n 选项,不首先查询远程头。
  • prune:删除与 <name> 关联的过期引用。

    • 使用 --dry-run 选项,报告将被修剪的分支但不实际修剪。
  • update:获取仓库中远程或远程组的更新。

    • 使用 --prune 选项,对所有更新的远程运行修剪。

讨论

远程配置使用 remote.origin.urlremote.origin.fetch 配置变量实现。

退出状态

成功时,退出状态为 0。当子命令(如 addrenameremove)找不到相关远程时,退出状态为 2。当远程已存在时,退出状态为 3

示例

bash
# 添加新远程、获取并从中检出分支
$ git remote
origin
$ git remote add staging git://git.kernel.org/.../gregkh/staging.git
$ git fetch staging

# 模拟 `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-fetch(1), git-branch(1), git-config(1)

Git

git 套件的一部分

基于 CC BY-NC-SA 3.0 许可发布