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 assembla.com
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 >
and origin
are.
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.
Note: if your master
branch is already tracking origin/master
(you can see that with git branch -avvv
, or a longer alias), then a git merge
will not display anymore:
fatal: No commit specified and merge.defaultToUpstream not set.
The next Git 2.à.x (Q3 2014) will remove that error message:
see commit a01f7f2 by Felipe Contreras (felipec
):
merge
: enable defaulttoupstream
by defaultThere's no point in this:
% git merge fatal: No commit specified and merge.defaultToUpstream not set.
We know the most likely scenario is that the user wants to merge the upstream, and if not, he can set
merge.defaultToUpstream
to false.
That means you won't need anymore to do a:
git config merge.defaultToUpstream true
As noted with Git 2.33 (Q3 2021): Defaults to true.
See commit 8603c41 (07 Jun 2021) by Felipe Contreras (felipec
).
(Merged by Junio C Hamano -- gitster
-- in commit 11fac26, 08 Jul 2021)
Signed-off-by: Felipe Contreras
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With