git push后提示warning: push.default is unset

在新装git没有完全配置完成的时候,使用git push会有以下提示信息:

warning: push.default is unset; its implicit value is changing in Git 2.0 from ‘matching’ to ‘simple’. To squelch this message and maintain the current behavior after the default changes, use:

git config –global push.default matching

To squelch this message and adopt the new behavior now, use:

git config –global push.default simple

When push.default is set to ‘matching’, git will push local branches to the remote branches that already exist with the same name.

出现这个提示的原因是git现在不知道需要提交多少个分支的代码,是当前分支,还是所有分支。

可以修改git配置中的push.default属性来确定git push的默认提交方式,在Git 2.0之前,这个属性默认为matching,2.0版本之后,默认为simple。正是因为这个改动,才会出现这个提示信息。

我们可以使用下面这条命令来更改push.default的值:

$ git config --global push.default 'option'

‘option’是要设定的值,push.default有以下几个可选值:

nothing, current, upstream, simple, matching

各个属性含义分别是:

  • nothing - 在不显示指定远程分支的情况下,git push命令无效。

  • current - push当前分支到远程仓库中的同名分支,如果远程仓库中不存在此分支,则自动创建该分支。

  • upstream - push当前分支到其upstream分支。

  • simple - 与upstream属性相似,但是如果本地分支与远程upstream分支不同名,则拒绝push操作。

  • matching - push本地与远程都存在的同名分支。

upstream分支

上面提到了一个upstream分支,下面解释一下它的含义:

git中存在upstream和downstream,简言之,当我们把仓库A中某分支x的代码push到仓库B分支y,此时仓库B的这个分支y就叫做A中x分支的upstream,而x则被称作y的downstream,这是一个相对关系,每一个本地分支都相对地可以有一个远程的upstream分支(注意这个upstream分支可以不同名,但通常我们都会使用同名分支作为upstream)。

初次提交本地分支,例如git push origin develop操作,并不会定义当前本地分支的upstream分支,我们可以通过git push –set-upstream origin develop,关联本地develop分支的upstream分支,另一个更为简洁的方式是初次push时,加入-u参数,例如git push -u origin develop,这个操作在push的同时会指定当前分支的upstream。

注意push.default = current可以在远程同名分支不存在的情况下自动创建同名分支,有些时候这也是个极其方便的模式,比如初次push你可以直接输入 git push 而不必显示指定远程分支。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值