Git从GitHub中抽取某个分支 [英] Git pull a certain branch from GitHub
问题描述
实际上我的答案是:
在Git中推拉分支
但我收到一个错误![rejected]和一些关于非快进的内容。
有什么建议吗?
但是我得到一个错误![rejected]和一些关于非快进 b $ b
这是因为Git无法将来自分支的更改合并到当前主控中。假设您已经检出分支 master
,并且您想要合并到远程分支 other-branch
中。当你这样做时:
$ git pull origin other-branch
Git基本上是这样做的:
$ git fetch origin other - 分支&& git merge other-branch
即 pull
只是一个 fetch
,然后是 merge
。然而,当 pull
-ing时,Git将仅合并其他分支
如果它可以执行快进合并。快进合并是一种合并,您要合并的分支的头部是要合并的分支头部的直接后代。例如,如果你有这个历史树,那么合并 other-branch
会导致一个快进合并:
OOOOOO
^ ^
其他分支
然而,这不会是一个快进合并:
v master
OOO
\
\-OOOO
^其他分支
为了解决您的问题,首先获取远程分支:
$ git获取原点其他分支
然后将它合并到您当前的分支中(我假设它是<$ c
$ p $ git merge origin / other-> $ c $ master $ $ git merge origin / other-分支
#修复合并冲突(如果发生)
#添加合并冲突修正
$ git commit#并提交合并!
I have a project with multiple branches. I've been pushing them to GitHub, and now that someone else is working on them I need to do a pull from GitHub. It works fine in master. But say I have branch xyz. How can I pull branch xyz from GitHub and merge it into branch xyz on my localhost?
I actually have my answer here: Push and pull branches in Git
But I get an error "! [rejected]" and something about "non fast forward".
Any suggestions?
But I get an error "! [rejected]" and something about "non fast forward"
That's because Git can't merge the changes from the branches into your current master. Let's say you've checked out branch master
, and you want to merge in the remote branch other-branch
. When you do this:
$ git pull origin other-branch
Git is basically doing this:
$ git fetch origin other-branch && git merge other-branch
That is, a pull
is just a fetch
followed by a merge
. However, when pull
-ing, Git will only merge other-branch
if it can perform a fast-forward merge. A fast-forward merge is a merge in which the head of the branch you are trying to merge into is a direct descendent of the head of the branch you want to merge. For example, if you have this history tree, then merging other-branch
would result in a fast-forward merge:
O-O-O-O-O-O
^ ^
master other-branch
However, this would not be a fast-forward merge:
v master
O-O-O
\
\-O-O-O-O
^ other-branch
To solve your problem, first fetch the remote branch:
$ git fetch origin other-branch
Then merge it into your current branch (I'll assume that's master
), and fix any merge conflicts:
$ git merge origin/other-branch
# Fix merge conflicts, if they occur
# Add merge conflict fixes
$ git commit # And commit the merge!
这篇关于Git从GitHub中抽取某个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!