git - 如何找到当前分支跟踪的分支

标签 git

我想弄清楚如果我在当前分支中执行 git fetch 将获取哪个分支,以及如何更改它(通过 git remote 的某些变体) > 或编辑 .git/config 文件)。

git pull 从哪个远程分支获取内容? git fetch 从中获取内容是否相同?有没有可以显示所有这些信息的 git 命令?

最佳答案

为本地分支使用设置跟踪的远程分支

git branch --set-upstream <local_branch> <remote_branch>

因此,如果您想要本地 master跟踪origin/master , 输入

git branch --set-upstream master origin/master

然而,git fetch获取已配置远程的所有分支。

如果您有多个 Remote (例如 originother ),

git fetch other

将获取远程 other同时

git fetch origin

将获取 origin .

要找出正在跟踪哪个远程分支,请打开 .git/config并搜索像

这样的条目
[branch "mybranch"]
  remote = <remote_name>
  merge = <remote_branch>

这告诉您本地分支机构 mybranch<remote_name>作为远程配置,它跟踪 <remote_branch><remote_name> .

从远程获取哪些分支以及它们在本地存储库中的调用方式在 .git/config 的以下部分中定义。 :

[remote "origin"]
  fetch=+refs/heads/*:refs/remotes/origin/*
  url=<url_of_origin>

这告诉您存储在 refs/heads 下的分支您的来源被获取并存储在 refs/remotes/origin/ 下在您的本地存储库中。

如果您在 mybranch然后输入 git fetch , 的修订 <remote_name> (在 [remote <remote_name>] 部分中指定)将被提取。如果您键入 git pull , 在获取 <remote_name> 的修订后分行<remote_branch><remote_name>将 merge 到mybranch .

更多信息可以在 git branch 的手册页中找到, git fetch git pull .

关于git - 如何找到当前分支跟踪的分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6921773/

相关文章:

git - 在 git 中压缩提交是什么意思?

git - TortoiseGit - 慢速显示日志修改查询

linux - 我想添加本地仓库的远程分支?

Git 推送错误 : does not match your user account

git - sourcetree 行结束问题

git - `.gitignore` 文件中前导斜杠的含义

git - 如何将主分支与另一个分支及其提交一起切换?

git - 是否有撤消 git init 的命令?

git - 有没有办法使用 GUI 工具查看完整的 git diff?

git - GitHub 如何通过存储库 merge 基于 Web 的 Wiki 编辑?