1. 程式人生 > >Updates were rejected because the remote contains work that you do hint: not have locally. This is u

Updates were rejected because the remote contains work that you do hint: not have locally. This is u

今天在學習git時,

$  sudo git push origin master  

報錯了:

To https://github.com/xxxxx/xxxx.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/xxxx/xxxxx.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.

解決很簡單,

$ sudo git pull origin master  //將原生代碼先更新到和github上的一樣

warning: no common commits
remote: Counting objects: 3
, done. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/xxxxx/xxxx * branch master -> FETCH_HEAD * [new branch] master -> origin/master Merge made by the 'recursive' strategy. hello_world.txt | 1 + 1 file
changed, 1 insertion(+) create mode 100644 hello_world.txt

會自動開啟一個GUN 什麼的編輯介面,ctrl + x退出就好

$  sudo git push origin master  //將原生代碼push到github上

Username for 'https://github.com': xxxx
Password for 'https://[email protected]':
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 522 bytes | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To https://github.com/xxxx/xxxx.git
   e8064b2..c2bab39  master -> master

程式碼已經成功上傳到了github上,問題解決了。