建立專(zhuān)案時(shí)出現(xiàn)問(wèn)題,大家看看我哪一步出錯(cuò)了
本地編寫(xiě)程式碼
#github上建立新項(xiàng)目,並且用github直接 建立了readme.md
#git remote add origin git@github.com:xxx/xxx
#git push -u origin master
到這裡,開(kāi)始報(bào)錯(cuò):
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
,又報(bào)錯(cuò):
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
這到底哪裡出錯(cuò)了?正確推送git項(xiàng)目的姿勢(shì)是什麼呀
你的第二次錯(cuò)誤解決如下
[問(wèn)題]fatal: refusing to merge unrelated histories
[解決]git pull origin master --allow-unrelated-histories
使用git的正確姿勢(shì)是
1. git init
2.git add .
3.git commit -m '注釋'
4. git remote add origin httpsxxxx
5.git pull origin master
6. git push -u origin master
通常來(lái)說(shuō),倉(cāng)庫(kù)只能有一個(gè)初始提交點(diǎn),而你這裡透過(guò)Github創(chuàng)建了一個(gè)初始提交,又在本地創(chuàng)建了一個(gè)初始提交,自然在本地進(jìn)行推送的時(shí)候會(huì)報(bào)錯(cuò)。
如果你在Github創(chuàng)建專(zhuān)案的時(shí)候,選擇了透過(guò)readme之類(lèi)的方式初始化了倉(cāng)庫(kù),你本地應(yīng)該透過(guò)克隆遠(yuǎn)端倉(cāng)庫(kù)到本地,而不是創(chuàng)建一個(gè)新倉(cāng)庫(kù)並綁定遠(yuǎn)端倉(cāng)庫(kù)。
如果你在Github上建立專(zhuān)案的時(shí)候,沒(méi)有選擇倉(cāng)庫(kù)初始化選項(xiàng),你可以在本地建立一個(gè)新倉(cāng)庫(kù),並綁定遠(yuǎn)端倉(cāng)庫(kù),把本地的初始提交推送到遠(yuǎn)端倉(cāng)庫(kù)。