1. 程式人生 > >Git提交到GitHub報錯:Updates were rejected because the remote contains work that you do not have locally

Git提交到GitHub報錯:Updates were rejected because the remote contains work that you do not have locally

轉自:https://blog.csdn.net/u011284073/article/details/81609707 

在使用Git將本地專案上傳到GitHub上時,鍵入命令:

git push -u origin master
報錯提示:Updates were rejected because the remote contains work that you do not have locally,This is usually caused by another repository pushing to the same ref. You may want to first integrate the remote changes (e.g., 'git pull ...') before pushing again.

究其原因,是因為本寶寶在GitHub上建立遠端倉庫時,勾選了 Initialize this repository with a README這項,導致遠端倉庫不為空,解決辦法,先將遠端倉庫的內容合併到本地,然後再上傳即可,命令如下:

git pull --rebase origin master
git push -u origin master