今天像往常一樣進行git遠程推送蛉迹,在GitHub上的倉庫是存在的序矩,git push時結果出現(xiàn)以下報錯:
$ git push -u origin masterTo git@github.com:xxx/xxx.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:xxx/xxx.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
經(jīng)過一番冥思苦想并查資料后奸晴,發(fā)現(xiàn)這只是因為有遠程庫中的文件沒有下載下來!
所以需要先運行:
git pull origin master
然后就看到了遠程文件已經(jīng)下載到你的工程里面并且自動合并了椭岩。
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 5 (delta 4), reused 5 (delta 4), pack-reused 0
Unpacking objects: 100% (5/5), done.
From github.com:xxxx/demo-test1
* branch master -> FETCH_HEAD
ffdc5ca..f30f5a3 master -> origin/master
Auto-merging package.json
Auto-merging .idea/workspace.xml
CONFLICT (content): Merge conflict in .idea/workspace.xml
Automatic merge failed; fix conflicts and then commit the result.
如遇到merge failed根據(jù)提示git commit 操作就可以了贼涩。
接下來就可以正常在本地庫中添加新文件并且提交,
最后,運行
git push -u origin master
Done 成功薯蝎!