前言
你是否因为git复杂的配置而头疼过?是否因为提交不上代码或者拉取不下代码而烦躁过?是否因为github访问不到而导致拉取项目443等问题?当你本地存在多个项目,同时存在公司项目以及GitHub项目,是否有过用户名提交错乱等问题?本文将会从根本上解决你的上述问题,带你快速清晰的理解git”复杂的”配置。
快速理解git配置
git配置有system(系统级别) global(用户级别)和local(当前仓库)三个 设置先读取【system】然后是【global】最后是【local】,因此相同配置后面读取的会覆盖之前读取的,分别使用 git --system/global/local --list
可以定位到相应的配置文件
1 2 3 4 5 6
| # 查看系统config git config --system --list # 查看当前用户(global)配置 git config --global --list # 查看当前仓库配置信息 git config --local --list
|
为Git配置代理
可以参考相关文章:解决git无法clone提示443以及配置git代理方法
1 2 3 4 5 6 7 8 9 10 11
| # 添加当前仓库配置: git config --local http.proxy "127.0.0.1:1087" # 为当前仓库添加用户名和邮箱地址 git config --local user.name "userName" git config --local user.email "email address" # 删除当前仓库配置: git config --unset --local http.proxy # 添加全局配置: git config --global http.proxy "127.0.0.1:1087" # 删除全局配置: git config --unset --global http.proxy
|
注:添加相关配置也可以到本地项目目录中,找到【.git文件夹】中的config文件,此文件中的配置即为local级别的配置,如果对单个项目配置代理,就可以在对应项目下的文件中添加下面的配置即可
- 仓库级的配置文件:在仓库的
.git/.gitconfig
,该配置文件只对所在的仓库有效
- 全局配置文件:Mac 系统在
~/.gitconfig
,Windows 系统在 C:Users<用户名>.gitconfig
- 系统级的配置文件:在 Git 的安装目录下(Mac 系统下安装目录在
/usr/local/git
)的 etc
文件夹中的 gitconfig
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin"] url = https://github.com/lizejiao/dog-egg-sample.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [user] name = 李苟蛋 email = 8346132@qq.com [http] proxy = http://127.0.0.1:7890
|
版权声明: 此文章版李苟蛋所有,如有转载,请注明来自原作者!