How to pull from another remote branch in git

I am trying to pull from one branch in the remote name "front" to a branch named "back":

git checkout front git pull 

But I get an error like

 Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch>. 

What should I do now? Thanks in advance.

+6
source share
3 answers
  • configure remote branch

git remote add origin git@github.com :user/repo.git

  1. pull it

git pull origin front

  1. create your own branch (if the back already exists, don't worry with the -b flag)

git checkout -b back

  1. merging front to back

git merge front

+2
source

It looks like you're trying to git merge merge two branches.

Here is the documentation for your convenience: https://git-scm.com/docs/git-merge

Since you are trying to merge the "front" into the "back", you need to go back. This can be done using the following command: git checkout back

Once you select back, just use the merge command to merge the two branches: git merge front

The git pull command git pull information from a remote repository to update the local repository. It is not going to pull from any branches, only the branch that you have currently checked. It sounds promising, but actually it is not.

Take a look at this post to learn more about git pull and git fetch : What is the difference between 'git pull' and 'git fetch'? . It is wonderful!

0
source

Other answers do a great job explaining how to merge branches when you pull or remove them from the remote. All of them assume that your branches have the same name in both repositories, but this is not required for Git.

In order for the local branch "back" to pull out and click on the remote branch "front", you just need to configure tracking correctly:

 git checkout -b back origin/front 

will create a new local branch "back", which will pull from the remote "front". You can also configure an existing local branch with

 git branch --set-upstream-to=origin/front back 

The last argument is not required if you currently checked back. See fooobar.com/questions/229 / ... for details on setting up branches.

0
source

Source: https://habr.com/ru/post/1014072/


All Articles