Git: error: src refspec master does not match any.

I tried to commit and push one of my projects to Git repository, but met the error:

error: src refspec master does not match any.
error: failed to push some refs to ‘https://xxxxx.com/repo’

I found a correct way to initialize connect local git repository and connect it with remote one.
1. $ cd /path/to/project
2. $ git init
3. $ git remote add origin https://xxxxx.com/repo
4. $ git add .
5. $ git commit -m ‘initial commit’
6. $ git push origin master

That’s it!