git报错:fatal: bad config variable ‘push.default‘ in file ‘/Users/username/.gitconfig‘ at line 6

问题描述:

error: malformed value for push.default: option
error: must be one of nothing, matching, simple, upstream or current
fatal: bad config variable ‘push.default’ in file ‘/Users/username/.gitconfig’ at line 6

原因分析:

为什么git版本不同会有两种不同的push行为?

因为在git的全局配置中,有一个push.default属性,其决定了git push操作的默认行为。在Git 2.0之前,这个属性的默认被设为’matching’,2.0之后则被更改为了’simple’。

我们可以通过git version确定当前的git版本(如果小于2.0,更新是个更好的选择),通过git config --global push.default 'option'(这里option有以下5个选项值)改变push.default的默认行为(或者也可直接编辑~/.gitconfig文件)。

push.default 有以下几个可选值:
nothing, current, upstream, simple, matching

其用途分别为:

  • nothing - push操作无效,除非显式指定远程分支,例如`git push origin develop。
  • current - push当前分支到远程同名分支,如果远程同名分支不存在则自动创建同名分支。
  • upstream - push当前分支到它的upstream分支上(这一项其实用于经常从本地分支push/pull到同一远程仓库的情景,这种模式叫做central workflow)。
  • simple - simple和upstream是相似的,只有一点不同,simple必须保证本地分支和它的远程
    upstream分支同名,否则会拒绝push操作。
  • matching - push所有本地和远程两端都存在的同名分支。

因此如果我们使用了git2.0之前的版本,push.default = matching,git push后则会推送当前分支代码到远程分支,而2.0之后,push.default = simple,如果没有指定当前分支的upstream分支,就会收到上文的fatal提示。

解决方案:

  1. 通过git config --global push.default matching命令改变push.default的默认行为
  2. 或者也可直接编辑~/.gitconfig文件,修改push.default 的值。
    在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值