I clone my repository with:
git clone ssh://xxxxx/xx.git
But after I change some files and add
and commit
them,
I also had a similar error after deleting all files on my local computer, and I have to clean up all files in the repository.
My error message was something like this:
error: src refspec master does not match any.
error: failed to push some refs to 'git@github ... .git'
And it was solved by executing the following commands:
touch README
git add README
git add (all other files)
git commit -m 'reinitialized files'
git push origin master --force # <- caution, --force can delete others work.
I also followed GitHub's directions as follows below, but I still faced this same error as mentioned by the OP:
git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master
For me, and I hope this helps some, I was pushing a large file (1.58 GB on disk)
on my MacOS. While copy pasting the suggested line of codes above, I was not waiting for my processor to actually finish the add .
process. So When I typed git commit -m "message"
it basically did not reference any files and has not completed whatever it needs to do to successfully commit my code to GitHub.
The proof of this is when I typed git status
usually I get green fonts for the files added. But everything was red. As if it was not added at all.
So I redid the steps. I typed git add .
and waited for the files to finish being added. Then I followed through the next steps.
For me,following worked to move untracked files:
git add --all
Next, I followed similar steps
git commit -m "First commit"
Then,
git remote add origin git@github.....
Last but not the least:
git push -u origin master
As you do this, Windows security will pop up asking for your username and password.
Just add an initial commit. Follow these steps:
git add .
git commit -m "initial commit"
git push origin master
This worked for me.
git add .
is all you need. That code tracks all untracked files in your directory.
I found this happened in a brand new repository after I Git added only a directory.
As soon as I added a file (e.g. a README), Git push worked great.