2

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).

Community
  • 1
  • 1
BreakPhreak
  • 10,940
  • 26
  • 72
  • 108
  • `git branch --set-upstream /2012_05_09_my_branch 2012_05_09_my_branch` Note: is probably `origin` – Op De Cirkel Jun 03 '12 at 19:32
  • 1
    >>>_Why do I need to do `--set-upstream` all the time?_ - To create your local branch use: `git checkout --track remotes//` . This will create local branch named `` and upstream will be set automatically – Op De Cirkel Jun 04 '12 at 08:17

3 Answers3

2

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>

Op De Cirkel
  • 28,647
  • 6
  • 40
  • 53
  • thanks! sounds like this! will try it very soon and will mark the answer when it works. meanwhile - any idea on how could I get to this (strange for me) situation (where a branch becomes "unconnected")? I know and use only very basic commands (promise to improve in the near future :) – BreakPhreak Jun 04 '12 at 06:58
  • also, how can I know that any local branch is attached to the proper remote branch - which command do I need to run to get the info please? – BreakPhreak Jun 04 '12 at 06:59
  • 1
    @BreakPhreak `git for-each-ref --format='%(refname:short) <- %(upstream:short)' refs/heads` If there local branch not connected to remote you will get ` <-` – Op De Cirkel Jun 04 '12 at 07:18
  • and to the question on how a branch can become "unconnected" (please)? – BreakPhreak Jun 04 '12 at 07:44
  • @BreakPhreak I can not answer that question, there are many ways: 1) changing your `.git/config` 2) deleting then recreating the local branch 3) not setting it as _tracking_ branch in first place. etc, etc, etc – Op De Cirkel Jun 04 '12 at 07:47
  • thanks (underrstood). now applied your command and updated the main question (something is still /*done*/ wrong). – BreakPhreak Jun 04 '12 at 07:50
  • PS: IF you can - please look at "Update N2" – BreakPhreak Jun 04 '12 at 07:54
  • 1
    sorry, the arguments should be swapped. please read my updated answer answer, and redoit – Op De Cirkel Jun 04 '12 at 07:59
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/12099/discussion-between-breakphreak-and-op-de-cirkel) – BreakPhreak Jun 04 '12 at 08:01
0
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.

Kristof Jozsa
  • 6,612
  • 4
  • 28
  • 32
0

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
sensorario
  • 20,262
  • 30
  • 97
  • 159