2017-10-07 131 views
0

我被困在這段代碼中。在git fetch之後,我遇到了一堵牆,不知道下一步應該如何將所有提交的文件都放到GitHub服務器上 - 現在只有一個文件README.md在保存新存儲庫時自動創建。感謝幫助。GitBash |起源大師 - 拒絕(首先獲取)| GitHub存儲庫中沒有文件

Freeware [email protected] MINGW64 ~/Desktop/Coding Staff/MustBeDone (master) 
$ git status 
On branch master 
nothing to commit, working tree clean 

Freeware [email protected] MINGW64 ~/Desktop/Coding Staff/MustBeDone (master) 
$ git remote add origin https://github.com/adambugaj/Lets-code.git 

Freeware [email protected] MINGW64 ~/Desktop/Coding Staff/MustBeDone (master) 
$ git push -u origin master 
To https://github.com/adambugaj/Lets-code.git 
! [rejected]  master -> master (fetch first) 
error: failed to push some refs to 'https://github.com/adambugaj/Lets-code.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. 

Freeware [email protected] MINGW64 ~/Desktop/Coding Staff/MustBeDone (master) 
$ git fetch origin master 
warning: no common commits 
remote: Counting objects: 3, done. 
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 
Unpacking objects: 100% (3/3), done. 
From https://github.com/adambugaj/Lets-code 
* branch   master  -> FETCH_HEAD 
* [new branch]  master  -> origin/master 

GitBash code

+0

可能重複的[git:更新被拒絕,因爲遠程包含本地沒有的工作](https://stackoverflow.com/questions/24357108/git-updates-were-rejected-because-the-remote-contains-work-that-do-not-have) – phd

回答

1

如果你想保持你可以把它和重訂其

git pull --rebase origin master 

自述文件。然後如果你不把你的代碼回

git push origin master 

t希望自述文件只是強行推送它

git push origin master -f 
+0

因此,所有錯誤都是由自述文件產生的?我不應該創造這個比。感謝您提供快速響應和成功的解決方案。 – Adam

+0

在創建存儲庫時創建自述文件時,您正在進行提交。因此,您的本地回購和上游回購會在提交歷史中發生衝突。你必須使其中任一個與另一個一樣強制或通過rebase –

+0

我現在看到,謝謝你清除這個。 – Adam

1

看起來您只有默認的README.md文件,它與創建github repo一起提供。 我會說,因爲這是你的第一個承諾,並推到倉庫 先走一步,做一個力推

git push origin master -f 

存在的鮮庫工作的另一個更簡單的方法。 您可以先將git clone https://github.com/adambugaj/Lets-code.git放入任何本地存儲庫。然後將所有文件放在該目錄中(或者開始編碼),然後git push origin master將工作得很好。

初始克隆後,您可以根據需要編輯/刪除README.md文件。 (但它有一個README.md文件爲您的回購總是好的)

+0

感謝您的好解釋。如果我沒有在開始時創建自述文件,但在完成第一次提交後會更好嗎? – Adam

+0

哦,你總是有這個選擇。 _ **「使用自述文件初始化此存儲庫 這會讓您立即將存儲庫克隆到您的計算機。如果您要導入現有存儲庫,請跳過此步驟。」** _此複選框始終存在。但是,我在上面的回答中提到了相同的建議(讓該文件可以立即克隆) – codePrady

+0

好的,下次我不會再檢查。感謝您的解釋。 – Adam

相關問題