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

背景:

    最近将ubuntu更新到ubuntu16.04,然后git了几个项目,发现提交修改时总是报错,fatal: 'origin' does not appear to be a git repository。我以前用ubuntu14.04时从来没遇到过这样的错误,一时不知如何解决。

    网上搜索了一下,有使用以下方法的:

    输入: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上的项目地址。

    其实我也不知道ubuntu16.04上为啥git pull时config文件的信息是不全的,之前并没有遇到过,这里做个记录。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值