git git push origin master时出错:fatal: 'origin' does not appear to be a git repository

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 这个错。

解决方法如下:

远程分支上存在本地分支中不存在的提交,往往是多人协作开发过程中遇到的问题,可以先fetchmerge,也就是pull,把远程分支上的提交合并到本地分支之后再push

如果你确定远程分支上那些提交都不需要了,那么直接git push origin master -f,强行让本地分支覆盖远程分支。。。

 


原文:https://segmentfault.com/q/1010000002736986
原文:https://blog.csdn.net/github_37157365/article/details/79850747 

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值