git 好像不用了,想再次使用的時候報git push origin master時出錯:fatal: 'origin' does not appear to be a git repository錯誤
網上搜索了一下,有使用以下方法的:
輸入:git remote add origin [email protected]:yourusername/test.git,然後再重新提交,其中yourusername就是github的賬號,test就是需要提交代碼的倉庫名。
我使用了之後報了一個倉庫已存在的結果。
然後在網上找到另一個方法:
對比.git/config文件
之後我查看.git目錄下的config文件發現了問題所在,只有[core],沒有[remote "origin"]和[branch "master"]信息。
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
也就是說當你git push origin master的時候,git需要去config中查找你提交的分支信息,但是config中又是空的,所以返回上述錯誤。
所以解決方法就是把信息填上:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://github.com/VizXu/GobangGame
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
其中url對應的就是你github上的項目地址。
之後就成功了。
因爲我之前亂搞有上傳過東西,所以又報了 hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused 這個錯。
解決方法如下:
遠程分支上存在本地分支中不存在的提交,往往是多人協作開發過程中遇到的問題,可以先fetch
再merge
,也就是pull
,把遠程分支上的提交合併到本地分支之後再push
。
如果你確定遠程分支上那些提交都不需要了,那麼直接git push origin master -f
,強行讓本地分支覆蓋遠程分支。。。
原文:https://segmentfault.com/q/1010000002736986
原文:https://blog.csdn.net/github_37157365/article/details/79850747