Confusing error message from git

GitGithub

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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.

Solution 3 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncinekView Question on Stackoverflow
Solution 1 - Gitp4bl0View Answer on Stackoverflow
Solution 2 - GitAristotle PagaltzisView Answer on Stackoverflow
Solution 3 - GitTomek SzpakowiczView Answer on Stackoverflow