1

I have a local git repo with many commits. I created an empty repo in github (not initialized with any files).

$ git remote add origin https://github.com/bar/foo.git
$ git push -u origin master
Counting objects: 35, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (35/35), 1.95 KiB | 0 bytes/s, done.
Total 35 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
remote: bar/foo
remote: fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
remote: Use '--' to separate paths from revisions, like this:
remote: 'git <command> [<revision>...] -- [<file>...]'
remote: master
To https://github.com/bar/foo.git
 * [new branch]      master -> master

My changes are in remote and things seem to have worked fine. Still, why do I get a "fatal" error ?

remote: fatal: ambiguous argument 'master': unknown revision or path not in the the working tree.

softwarematter
  • 28,015
  • 64
  • 169
  • 263
  • Did you made the first commit? – Shihe Zhang May 08 '17 at 07:46
  • Yes, my local repo has many commits. Remote repo was newly created hence no commits at the time of push. – softwarematter May 08 '17 at 07:47
  • so it's actually two repo.you may need to pull the remote repo first. – Shihe Zhang May 08 '17 at 07:49
  • I am sure if I clone the repo and then add my changes and then push, I won't get the fatal error. But here since I have the repo, creating a remote and pushing to it seems like a valid use case and it worked fine. The "fatal" error just seems out of place. – softwarematter May 08 '17 at 07:54
  • You have a repo then it's not compatible with the later created remote repo.The `.git` dir would be a mess,since they wouldn't merge clean and clear.So they just forbid you to make them merge. – Shihe Zhang May 08 '17 at 08:02
  • What do you mean by "`.git` directory would be a mess"? It did not forbid me from merging. It pushed just fine despite the fatal error. – softwarematter May 08 '17 at 08:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/143663/discussion-between-shihe-zhang-and-devnull). – Shihe Zhang May 08 '17 at 08:05

1 Answers1

0

Part of the push -u command failed, but it shouldn't be a problem, it's a separate task. You can now try running:

git branch --set-upstream- master origin/master

or, in newer git versions:

git branch --set-upstream-to master origin/master

to set it manually. Be sure to adjust branch names to those you really used. The first argument here is the name of local branch that will be configured, and the second is the target that push will now point to by default.

So, in the example above, we're setting local master to push by default to origin/master. This is what push -u origin master would do. If your local repo is OK and if it has 'master' branch, then this command should simply succeed with no errors (and by the way, push-u should have as well back then).

If this command fails, you should review what branches and tracking references and upstreams etc you have configured in your local repo - something will be not right!

Maybe i.e. you don't have 'master' branch locally?

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107