GitHub使用過程中遇到的坑(已解決)

1、錯誤 ! [rejected] master -> master (non-fast-forward)

error: failed to push some refs to ‘[email protected]:Try-your-best-to-do/Myjava.git’
hin
問題(Non-fast-forward)的出現原因在於:git倉庫中已經有一部分代碼,所以它不允許你直接把你的代碼覆蓋上去。

1. 強推,即利用強覆蓋方式用你本地的代碼替代git倉庫內的內容

git push -f

2,先把git的東西fetch到你本地然後merge後再push

$ git fetch
$ git merge

這2句命令等價於

$ git pull  

2、fatal: remote origin already exists.

解決辦法如下:
1、先輸入$ git remote rm origin
2、再輸入$ git remote add origin [email protected]:(github帳號名)/(項目名).git 就不會報錯了!
3、如果輸入$ git remote rm origin 還是報錯的話,error: Could not remove config section ‘remote.origin’. 我們需要修改 gitconfig 文件的內容
4、找到你的 github 的安裝路徑
5、找到一個名爲gitconfig的文件,打開它把裏面的[remote “origin”]那一行刪掉就好了!

3、fatal: Couldn’t find remote ref master或者fatal: ‘origin’ does not appear to be a git repository以及fatal: Could not read from remote repository.

解決:

則需要重新輸入$ git remote add origin [email protected]:(github帳號名)/(項目名).git

注意是GitHub的賬戶名,我一直寫到配置時的 username 所以一直沒有解決!!!

參考鏈接:
https://www.jianshu.com/p/feb3a14c24ef

https://blog.csdn.net/su1573/article/details/78282813

https://www.jianshu.com/p/8d26730386f3

https://www.runoob.com/w3cnote/git-guide.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章