John Little John Little - 1 month ago 5x
Git Question

"No commit specified and merge.defaultToUpstream not set"

As a new git user, who is an expert with SVN and CVS, I am struggling to get the most basic of git functions to work.

I'm using a shared repo at

I created a local clone, and added a file:

$ git clone repository-url
$ echo "hello" > ha.txt
$ git add -A
$ git commit -a -m "haha"
$ git push

NOTE: at this point I got "No refs in common and none specified; doing nothing" error.
After some hours googling, I found the solution was to type this

$ git push origin master

Then I went onto another computer, modified the file, and commit-ed it (surprisingly, I didn't need to do the git push origin magic).
Then I back to the main computer, modified it again, so I could see how merge works.

$ git fetch
$ git merge

Now I get the error:

fatal: No commit specified and merge.defaultToUpstream not set.

Looking at the man page for "git merge", you have to specify something like this:

$ git merge [< commit >..]

The problem is, I cant find out what
< commit >
means, and what it should be. E.g. should it be a file, a repo, a message, a version?

I have not created a branch - I'm just working on the "head" or master as I think git calls it

Unfortunately, google is not much help on this one. The man pages seem to expect you to know what a
< refspec >
< commit >

Any help on this noob problem appreciated.


Usually you do not invoke git merge without arguments (at least I don't know anyone who does). If you want that merge defaults to the tracking branch, you need to set merge.defaultToUpstream to true: git config merge.defaultToUpstream true. Your master branch has to track origin/master in this case: git branch --set-upstream master origin/master. This is done automagically if origin/master was already present when you cloned.

Personally, I do git fetch and then git merge origin/master or git pull if I have no local commits.

Edit: As VonC mentioned merge.defaultToUpstream defaults to true since Git 2.0.