我想弄清楚如果我在当前分支中执行 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 (例如 origin
和 other
),
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/