git 好像不用了,想再次使用的时候报git push origin master时出错:fatal: 'origin' does not appear to be a git repository错误
网上搜索了一下,有使用以下方法的:
输入:git remote add origin git@github.com: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