【笔记】Git配置

前言

Git配置学习笔记

通过git config命令修改Git配置

--local:缺省值,本地配置,表示仅当前Git仓库的Git操作生效
--global:全局配置,表示当前用户的所有Git操作都生效
--system:系统配置,表示所有用户的所有Git操作都生效

查看所有配置

1
git config --list

配置身份

统一配置

1
git config --edit

单独配置

配置用户名

<username>:用户名

--global:全局配置

1
git config user.name "<username>"
配置邮箱

<email>:邮箱

--global:全局配置

1
git config user.email "<email>"

配置别名

  • git <command>改为使用git <alias>

--global:全局配置

1
git config alias.<alias> <command>
1
git <alias>

配置拉取策略

--global:全局配置

1
git config pull.rebase false
1
git config pull.rebase true
1
git config pull.ff only

配置推送策略

simple:缺省值,推送当前分支到上游同名分支,如果没有则不推送
upstream:推送当前分支到上游同名分支,如果没有则创建
current:推送当前分支到远程同名分支

1
git config push.default upstream

重置用户名密码信息

1
git config --unset credential.helper

配置代理

为所有域名配置代理

HTTP代理
1
2
git config http.proxy "http://<ip>:<port>"
git config https.proxy "http://<ip>:<port>"
SOCKS5代理
1
2
git config http.proxy "socks5://<ip>:<port>"
git config https.proxy "socks5://<ip>:<port>"
重置
1
2
git config --unset http.proxy
git config --unset https.proxy

为指定域名配置代理

HTTP代理
1
2
git config http.https://github.com.proxy "http://<ip>:<port>"
git config https.https://github.com.proxy "http://<ip>:<port>"
SOCKS5代理
1
2
git config http.https://github.com.proxy "socks5://<ip>:<port>"
git config https.https://github.com.proxy "socks5://<ip>:<port>"
重置
1
2
git config --unset http.https://github.com.proxy
git config --unset https.https://github.com.proxy

通过修改配置文件修改Git配置

本地配置

配置用户

.git/config
1
2
3
[user]
name = <name>
email = <email>

全局配置

配置代理

~/.gitconfig
1
2
3
4
[http]
proxy = http://<ip>:<port>
[https]
proxy = https://<ip>:<port>

完成

参考文献

GitHub——chuyik
抹茶酱的日常
稀土掘金——Mr丶Tony