git 如何在远程分支上获取最新信息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27588396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can I do a get latest on a remote branch?
提问by Pindakaas
I am trying to catchup with the latest code from a remote github branch. Suppose this branch is called myDevBranch how can I get this locally? I tried:
我试图赶上来自远程 github 分支的最新代码。假设这个分支叫做 myDevBranch 我怎样才能在本地得到它?我试过:
git fetch myDevBranch
This returns :
这返回:
fatal: 'myDevBranch' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Looks like a securuty issue or is there another way of getting the remote branch locally?
看起来像一个安全问题还是有另一种方法可以在本地获取远程分支?
回答by Mohammad AbuShady
You don't fetch a branch, you fetch
a remote, so the correct line would be
你不获取分支,你fetch
是一个遥控器,所以正确的行是
git fetch origin # or whatever your remote is called
Then the all tracking branches are updated, your updated code will be it a branch called origin/myDevBranch
, again origin is replaced with your upstream name
然后更新所有跟踪分支,更新后的代码将是一个名为 的分支origin/myDevBranch
, origin 再次替换为您的上游名称
To update your local branch you can merge the upstream git merge origin/myDevBranch
but you need to make sure that your HEAD
is pointing to your local branch of this remote (aka myDevBranch),
要更新您的本地分支,您可以合并上游,git merge origin/myDevBranch
但您需要确保您HEAD
指向此远程(又名 myDevBranch)的本地分支,
Or you can checkout to it git checkout origin/myDevBranch
but that would leave you in a detached head mode, you can create a new local branch from that remote using git checkout -b
或者您可以结帐到它,git checkout origin/myDevBranch
但这会使您处于分离的头部模式,您可以使用该远程创建一个新的本地分支git checkout -b
If your HEAD
is pointing to your current branch, then you can do a git pull
, keep in mind that pull
will do both fetch
and merge
, and if your branch has divergedfor any reason you would get a conflict
that you will need to resolve by your self.
如果您HEAD
指向当前的分支,那么您可以执行 a git pull
,请记住,这pull
将同时执行fetch
和merge
,如果您的分支因任何原因发生分歧,您将得到 a conflict
,您需要自己解决。
If you need to rebase
then you could either do a manual fetch
and rebase
or you could do a git pull --rebase
如果你需要,rebase
那么你可以做一个手册fetch
,rebase
或者你可以做一个git pull --rebase