2

I created a local repository for a C# project, and I've made a lot of commits to it over the past few days.

This evening I opened Git Bash so I could push the repo to Github for the first time. I've already created an empty repo in Github for this purpose.

I entered:

git push origin master

I was then prompted to enter my Github username and password. After that, I got this message:

warning: ignoring broken ref refs/heads/master.
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/myusername/myrepo.git'

I then ran git status, and under Changes to be committed: it showed all the tracked files as new files.

I ran git log and got this error:

fatal: bad default revision 'HEAD'

What's going on here, and how do I fix it?

UPDATE: I tried committing and got this message:

error: unable to resolve reference HEAD: No such file or directory
fatal: cannot lock HEAD ref
sigil
  • 8,744
  • 31
  • 107
  • 185

1 Answers1

3

You might not have done any commit in your local repo.
That would explain why HEAD refers to a "bad revision".

Add, git commit, and then push.

Make sure to use git 2.6+ (even on Windows): the error message should be more explicit now.
See "fatal: bad default revision 'HEAD'"

Let's detect this situation and write a more friendly message:

$ git log
fatal: your current branch 'master' does not have any commits yet

As the OP sigil comments below, it is easier to

  • "deleted the existing repo, ran git init, and committed successfully".
    That is delete the .git folder first.
    But in order to push, a git remote add origin https://url/to/remote/repo is required, before a git push -u origin master.

  • or clone the remote repo again, copy the files in the new local repo, add, commit and push.
    This is even easier, because the remote 'origin' is already set, and master is already linked to origin/master, so a simple git push is enough.
    (See "Why do I need to explicitly push a new branch?" for more)

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • All my commits have been to the local repo, so there are many folders in the `.git/objects` folder. I am worried that if I add and commit, I will lose all the commits that I already made. – sigil Oct 30 '15 at 05:53
  • also, please see my update to the question, I cannot commit to this repo now. – sigil Oct 30 '15 at 05:56
  • OK. What git version are you using? On which OS? – VonC Oct 30 '15 at 06:05
  • git version 1.9.5.msysgit.1 on Windows 7. At this point I just decided that it was more important to just get my current files under source control, so i deleted the existing repo, ran git init, and committed successfully. – sigil Oct 30 '15 at 06:12
  • Good workaround. I have included it in the answer for more visibility. – VonC Oct 30 '15 at 06:18
  • @sigil I have aded another workaround in the answer. – VonC Oct 30 '15 at 07:30