問題
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,即可