cinek
cinek

Reputation: 1952

Confusing error message from git

I got this message from Git:

You asked to pull from the remote 'origin', but did not specify a branch. Because this is not the default configured remote for your current branch, you must specify a branch on the command line.

Can anyone explain it? and more important how to fix it?

Upvotes: 134

Views: 92547

Answers (3)

Aristotle Pagaltzis
Aristotle Pagaltzis

Reputation: 118089

To fix it, assuming you are on the master branch and want to pull the master branch from the origin remote, in new enough Git versions (1.8 or newer):

git branch -u origin/master master

(Analogously for other branches and/or remotes.)

If you can combine this with a push, it’s even shorter:

git push -u origin master

Thereafter, a plain git pull/git push will do what you expect.


During the Git 1.7 series, git branch didn’t have the -u switch (only git push did), and instead you had to use the much longer --set-upstream:

git branch --set-upstream master origin/master

Note the reversal of arguments compared to -u. I fumbled this order more than once.


All of these, by the way, are shorthands for doing the following, which you can still do explicitly:

git config branch.master.remote origin
git config branch.master.merge refs/heads/master

Before 1.7, you had to do it this way.

Upvotes: 107

Tomek Szpakowicz
Tomek Szpakowicz

Reputation: 14532

Message says exactly what it is about. Your current branch is not associated with (is not tracking) any branch in origin. So git doesn't know what to pull.

What to do? That depends...

In most usual situation you are working off some local branch xyz which branched from master which is cloned from origin's master. The usual way to resolve it is to switch to master and pull to synchronize it with origin and then come back to xyz and rebase master.

But in your situation you might want to do something else. We can't know it without knowing details of your branches and remotes and how you intent to use them.

Upvotes: 5

p4bl0
p4bl0

Reputation: 3906

You have to tell git which branch you want to pull from the "origin" remote repos.

I guess you want the default branch (master) so git pull origin master should fix your problem.

See git help branch, git help pull and git help fetch for more informations.

Upvotes: 129

Related Questions