Question

It's probably an already asked question, but I just don't know what are the right names to call the issue - so please guide me or answer (yes, I've seen this question but couldn't get too much from the answer).

I am trying to git pull but receiving the following message:

You asked me to pull without telling me which branch you
want to merge with, and 'branch.2012_05_09_my_branch.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:
    [branch "2012_05_09_my_branch"]
    remote = <nickname>
    merge = <remote-ref>

    [remote "<nickname>"]
    url = <url>
    fetch = <refspec>

See git-config(1) for details.

It probably looks like my working directory is kinda "hanging" without being attached to any branch, am I right? If so - please advice on how to get it connected back to the proper branch (2012_05_09_my_branch for example). Probably I am even wrong with that (being a total GIT newbie), in this case please explain what's happening and what can I do about it.

Refined question: what do I need to do to run git push and git pull successfully without getting the message above?

Update: when I run git branch I get:

* 2012_05_09_my_branch
  master

Which kinda probably means that I am on my local 2012_05_09_my_branch branch which is not connected to any of the remote branches?

Update N2: Why do I need to do `--set-upstream` all the time? - very worth reading as a complementary material (found only now).

Was it helpful?

Solution

It is not that your working dir is not attached to a branch, but you do not have setup what is peer branch on the remote for your local branch. You can "connect" them together with:

git branch --set-upstream 2012_05_09_my_branch remotes/<your remote>/2012_05_09_my_branch

Where < your remote > is the server server as defined in .git/config, usually (when working with one server) is origin

EDIT: the safer way is to use remotes/<remote>/<branch> instead of <remote>/<branch>

OTHER TIPS

git status

will help you find out on which branch you are (if any). The command

git branch

will give a list about the local branches you have (git branch -a lists the remote ones as well). And of course you can use

git checkout <branchname>

to turn your working copy to the chosen branch.

When you create a local branch, and want to put it on remote repository you need to run this command:

$ git push origin 2012_05_09_my_branch
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top