问题描述:
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提示。
解决方案:
- 通过
git config --global push.default matching
命令改变push.default的默认行为 - 或者也可直接编辑~/.gitconfig文件,修改push.default 的值。