问题描述
我理解运行git fetch <remote>
的想法,因为远程分支可以在git checkout <remote>/<branch>
中使用.
I understand the idea of running git fetch <remote>
, because the remote branches are then available with git checkout <remote>/<branch>
.
但是如果我刚刚跑步怎么办
But how does it work if I just run
git fetch path/to/other/repo
如何结帐相应的分支?请注意,该操作会以静默方式运行(即使使用--verbose
也是如此),并且不会创建任何新分支.
How can I checkout the corresponding branches? Note that the operation runs silently (even with --verbose
), and that no new branch is created.
编辑:需明确:我完全理解git如何与遥控器一起使用.我只是对这种替代语法git fetch path/to/remote
或git fetch <url>
感到好奇.应该如何运作?为什么不创建新分支?为什么即使在冗长的模式下它也无声地运行?预期用途是什么?
edit: just to be clear: I perfectly understand how git works with remotes. I'm just curious about this alternate syntax git fetch path/to/remote
, or git fetch <url>
. How is it supposed to work? Why does it not create new branches? Why does it run silently even in verbose mode? What is the intended usage?
推荐答案
我认为最好的解释(比文档更好)是,通过 JakubNarębski .
I think the best explanation (much better than the docs) is an answer to another question by Jakub Narębski.
基本上:
git fetch <path>
只是获取远程服务器的HEAD
分支,并将其本地存储到FETCH_HEAD
.
just fetches the HEAD
branch of the remote, and stores it locally into FETCH_HEAD
.
git fetch <path> <branch>
获取远程仓库中的分支并将其存储在FETCH_HEAD
中.
fetches the branch in the remote repo and stores it in FETCH_HEAD
.
JakubNarębski的答案描述了更高级的用法,但是,正如他所说,最好的获取方法是使用命名的遥控器.
More advanced usages are described in Jakub Narębski's answer, but, as he states himself, the best way to fetch is to use named remotes.
这篇关于git使用路径而不是远程获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!