[英]How to take a pull of a remote branch that has not been merged into master into a local branch?
There is a remote branch and I want to take a pull from that branch into one of my local branches. 有一个远程分支,我想从那个分支拉到我的一个本地分支。 How do I do that? 我怎么做?
What is wrong with this? 这有什么问题?
git checkout myLocalBranch
git pull remoteBranch myLocalBranch
git pull
is used to update your current branch to the latest version on the remote. git pull
用于将您当前的分支更新为远程服务器上的最新版本。 You can't just pull a branch into another one. 您不能只是将一个分支拉入另一个分支。 That's called merging! 这就是所谓的合并!
So you have to do this: 因此,您必须这样做:
git fetch origin
git merge origin/remoteBranch
and resolve the merge conflicts (if any). 并解决合并冲突(如果有)。 This will result in the state you asked for: your local branch will have the remote branch on top. 这将导致出现您要求的状态:您的本地分支将在顶部具有远程分支。
As @eckes pointed out in the comments (thanks!) you should first run git fetch origin
in order to tell git about remoteBranch
. 正如@eckes在评论中指出的(谢谢!),您应该首先运行git fetch origin
,以向git讲述remoteBranch
。
First lets see where your commands can be improved. 首先让我们看看您的命令可以改进的地方。
git checkout myLocalBranch
is used to switch to an existing branch named myLocalBranch. 用于切换到名为myLocalBranch的现有分支。 If myLocalBranch does not exist then it will result in an error. 如果myLocalBranch不存在,则将导致错误。
git pull remoteBranch myLocalBranch
Cannot be used to arbitrarily pull from any branch to any branch. 不能用于任意从任何分支拉到任何分支。 Syntax for pull command is the following where some-remote is generally 'origin' or any other configured remote repository. 以下是pull命令的语法,其中some-remote通常是“ origin”或任何其他已配置的远程存储库。
git pull <some-remote> myLocalBranch
will pull the branch on remote which is being tracked by myLocalBranch. 会将分支拉到myLocalBranch正在跟踪的远程站点上。
Coming to your problem which is to pull a specific branch from remote. 出现问题是要从远程拉特定分支。 So, you need to create a local branch, specify the remote repository and the remote branch which has to be tracked. 因此,您需要创建一个本地分支,指定远程存储库和必须跟踪的远程分支。
git checkout -b myLocalBranch origin/remoteBranch
Will create a new local branch with name myLocalBranch which will track remoteBranch of 'origin' repository. 将创建一个名为myLocalBranch的新本地分支,该分支将跟踪“原始”存储库的remoteBranch。 Now you have switched to myLocalBranch and the branch has been configured. 现在,您已切换到myLocalBranch,并且分支已配置。 Do a git pull
which pull your work from remote. 进行git pull
,从远程拉动您的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.