git push.default设置

本文详细介绍了Git中push.default配置选项的作用及不同值的意义。针对Git2.0中默认行为的变化,提供了具体设置建议,帮助用户理解如何正确配置以适应各种工作流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

git config设置:

git config --global user.email "you@example.com"

git config --global user.name "Your Name"

to set your account's default identity.



git push.default设置

1
2
$ git --version
git version 1.8.4.rc3

默认配置下,当使用git push命令而没有明确的指名本地分支和远程参考分支的情况下,会有如下提示:

1
2
3
4
5
6
7
8
9
10
11
12
13
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
 
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

git-config(1)有单独的一节讲push.default设置:

如果git push命令没有明确指定引用规格(refspec),也就是没有指定推送的源分支和目标分支,那么git会采用push.default定义的动作。
不同的值适用于不同的工作流程模式。

push.default可用的值如下:

  • nothing

    不推送任何东西并有错误提示,除非明确指定分支引用规格。强制使用分支引用规格来避免可能潜在的错误。

  • current

    推送当前分支到接收端名字相同的分支。

  • upstream

    推送当前分支到上游@{upstream}。这个模式只适用于推送到与拉取数据相同的仓库,比如中央工作仓库流程模式。

  • simple

    在中央仓库工作流程模式下,拒绝推送到上游与本地分支名字不同的分支。也就是只有本地分支名和上游分支名字一致才可以推送,
    就算是推送到不是拉取数据的远程仓库,只要名字相同也是可以的。在GIT 2.0中,simple将会是push.default的默认值。
    simple只会推送本地当前分支。

  • matching

    推送本地仓库和远程仓库所有名字相同的分支。
    这是git当前版本的缺省值。

一般来说simple够了,如果严格一点儿可以用nothing,这样来配置push.default

1
$ git config --global push.default simple

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值