Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusing error message from git

Tags:

git

github

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?

like image 422
cinek Avatar asked Jun 28 '10 14:06

cinek


People also ask

What is the U argument in git?

-u : The -u flag creates a tracking reference for every branch that you successfully push onto the remote repository. The local branch you push is automatically linked with the remote branch. This allows you to use commands such as git pull without any arguments.

What is git pull origin master?

git pull origin master will pull changes from the origin remote, master branch and merge them to the local checked-out branch. git pull origin/master will pull changes from the locally stored branch origin/master and merge that to the local checked-out branch.


2 Answers

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.

like image 127
p4bl0 Avatar answered Sep 27 '22 17:09

p4bl0


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.

like image 32
Aristotle Pagaltzis Avatar answered Sep 27 '22 18:09

Aristotle Pagaltzis