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. 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
.
First lets see where your commands can be improved.
git checkout myLocalBranch
is used to switch to an existing branch named myLocalBranch. If myLocalBranch does not exist then it will result in an error.
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.
git pull <some-remote> myLocalBranch
will pull the branch on remote which is being tracked by 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. Now you have switched to myLocalBranch and the branch has been configured. Do a git pull
which pull your work from remote.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.