Git 删除远程分支报错 error: Could not remove config section 'remote.origin' 解决办法

来源:互联网 发布:淘宝关联页是什么 编辑:程序博客网 时间:2024/05/02 02:31

这是我的Github新创建的一个Repository

echo # springDemo >> README.mdgit initgit add README.mdgit commit -m "first commit"git remote add origin https://github.com/xuxinpie/springDemo.gitgit push -u origin master

上面无非就是将本地工程同步到github上, 但再使用git remote add origin的时候可能会出现的如下错误

$ git remote addorigin git@github.com:xuxinpie/springDemo.git

错误提示:fatal: remote origin already exists.

解决办法:

$ git remote rm origin

然后在执行:$ git remote add origin git@github.com:xuxinpie/springDemo.git 就不会报错误了

如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容

找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!


 但是实际是我依然存在问题, 因为我的目录下gitconfig根本没有这一行,发现网上的解决方法都无法解决我的问题,自己思考了一下:

发现问题存在于自己的eclipse中的git插件,里面配置了remote origin, 所以每次操作的时候都会走默认的远程分支。

解决办法:打开eclipse-->windows-->perference-->Git-->Configuration

里面的User Settings里面删除对应的remote origin项(我的已删除,可以脑补一下)



删除之后再git bash里面重新$ git remote rm origin 成功。希望之前在eclipse中使用git插件配置过remote origin的同志们注意下,不要再踩这个坑了,

1 1