16

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

git checkout front
git pull

But i am getting error message 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..

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Jawakar Selvaraj
  • 179
  • 1
  • 1
  • 3

5 Answers5

10
  1. set up a remote branch

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

  1. pull it

git pull origin front

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

git checkout -b back

  1. merge front into back

git merge front

rozar
  • 111
  • 8
4

The other answers do a great job explaining how to merge branches once you pull or fetch them from the remote. They all assume that your branches have matching names in both repositories, but this is not required by Git.

To have a local branch "back" pull from and push to a remote branch "front", you just need to set up the tracking properly:

git checkout -b back origin/front

will create a new local branch "back" that will pull from remote "front". You can also set up an existing local branch with

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

The last argument is not necessary if you currently have "back" checked out. See https://stackoverflow.com/a/2286030/2988730 for lots more information on setting up your branches.

Community
  • 1
  • 1
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
1

It sounds like you're trying to git merge the two branches together.

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

Since you're trying to merge "front" into "back", you need to checkout back. That can be accomplished by using this command: git checkout back

Once you have "back" checked out, just use the merge command to bring the two branches together: git merge front

The command git pull brings down information from the remote repository to update your local repository. It's not going to pull from any branches, only the branch you have currently checked out. It sounds promising, but it really isn't.

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's a great read!

Community
  • 1
  • 1
Adam Young
  • 11
  • 5
1

If I understand your scenario, you are working in a branch named "back", and you want to pull changes from the "front" branch.

If that is what you want to achieve, you may try the following command (while in the "back" branch):

git pull origin front
Sam S
  • 168
  • 2
  • 8
0

When checking out to a new branch, it gives me the old git commit content. In order to get the new commit to the front branch from my back branch:

In Android studio, use the menu options to git pull. It gives the option to select the back branch from the dropdown. This is only when you have no changes in front branch. If you have new changes, you will have to commit or stash them.

ouflak
  • 2,458
  • 10
  • 44
  • 49
suresh ch
  • 33
  • 1
  • 10