Creating new git repo and pushing it to remote server is fairly easy.
mkdir my-project cd my-project git init
You can work with project localy. When you want to push it to remote server, then it is necessary to add remote repo url.
git remote add origin <MY-URL>
Now you can push it:
git push -u origin master
When it works. Hooray. Sometimes you may find following error:
error: src refspec master does not match any. error: failed to push some refs to '<MY-URL>'
The reason why this happens is not that obvious. :-)
Git creates master branch only after commit to your local repo. If you just initialize repo then there is no master. How to fix it?
Just add and commit at least one change to your repo and re-run push command. You can add e.g. .gitignore.
You can find more info at StackOverflow.
worked like a champ!
Thank you! This was exactly what I needed and fixed my issue :)
Thanks a lot. I banged my head for 30 minutes before getting this page.
Thanks man! I spent 2 days trying to setup my repository and it was just because I haven’t made any change before commit. lol
explained so well.. thanks
Perfect. This tip should be included on every site that talks about initializing a repository. Thank you.
Thanks!! Making an initial commit solved the refspec problem for me too :)
Could you give an example? where to add .gitignore?
@Gallics: Read more about .gitignore at: https://github.com/github/gitignore
It should be in the root directiory of project.
E.g. to exclude DLL from the project:
echo “>*.dll” >.gitignore
git add .gitignore
A quick google search and I ended up here. Solved the problem. Many thanks! :)
Excellent, thanks – nice friendly style also!