建立專案時出現問題,大家看看我哪一步出錯了
本地編寫程式碼
#github上建立新項目,並且用github直接 建立了readme.md
#git remote add origin git@github.com:xxx/xxx
#git push -u origin master
到這裡,開始報錯:
error: failed to push some refs to 'git@github.com:xxx'
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.
然後,git pull
,又報錯:
warning: no common commits
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From github.com:xxx
+ 8324a8d...8c9fdd4 master -> origin/master (forced update)
fatal: refusing to merge unrelated histories
這到底哪裡出錯了?正確推送git項目的姿勢是什麼呀
雷雷
你的第二次錯誤解決如下
使用git的正確姿勢是
通常來說,倉庫只能有一個初始提交點,而你這裡透過Github創建了一個初始提交,又在本地創建了一個初始提交,自然在本地進行推送的時候會報錯。
如果你在Github創建專案的時候,選擇了透過readme之類的方式初始化了倉庫,你本地應該透過克隆遠端倉庫到本地,而不是創建一個新倉庫並綁定遠端倉庫。
如果你在Github上建立專案的時候,沒有選擇倉庫初始化選項,你可以在本地建立一個新倉庫,並綁定遠端倉庫,把本地的初始提交推送到遠端倉庫。