问题
github新建仓库后,添加了readme.md后怎么上传文件
报错
执行git push origin master
Push rejected: Push to origin/master was rejected
执行git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
执行git pull origin master
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
解决思路
因为在github上新建仓库的时候,就添加了readme.md文件,之后在本地仓库添加了文件,此时本地仓库和远程仓库的内容是不一样的,需要先把远程仓库的readme.md拉取到本地。
解决方案
执行 git pull origin master --allow-unrelated-histories
之后在push,即可