[Github] 本地git push免用户名和密码的配置

本文介绍如何使用gitconfig命令进行全局配置,包括设置邮箱、用户名、密码管理方式及默认推送行为等,并解释了从Git2.0开始默认推送行为的变化。

 

在终端通过git config --global命令进行配置

git config --global user.email "xxx@xxmail.com"
git config --global user.name "xxx"
git config --global credential.helper store   # git push的时候记住用户名和密码
git config --global push.default simple       #从Git 2.0之后,push.default的默认值由'matching'改为'simple'

 

这几个命令实际上在操作用户目录下的.gitconfig文件, 其内容如下:

$ cat ~/.gitconfig 
[user]
    email = xxx@xxmail.com
    name = xxx
[credential]
    helper = store
[push]
    default = simple

 

另外,如果没有配置push.default这一项,git push的时候会提示以下信息,可以看到matching方式和simple方式的区别:

warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, 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.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

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)

 

参考:

解决`向github提交代码是老要输入用户名密码`

 

转载于:https://www.cnblogs.com/bymo/p/8250254.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值