Git Config
目录
1 配置级别
git config
有三个级别: system、global (用户, 全局生效) 和local (用户, 当前仓库), 优先级为system>global>local, 分别使用--system/global/local
参数来指定级别。
查看系统 (system) 的git config:
git config --system --list
查看用户全局 (global) 的git config:
git config --global --list
查看当前仓库 (local) 的git config:
git config --local --list
不使用参数时
如果不使用
--system/global/local
参数, 直接使用git config --list
命令, 则输出system+global+local的git config; 如果当前路径不是git仓库, 则只输出system+global的git config。2 配置用户
git config --global user.name "your_name"
git config --global user.email "[email protected]"
3 生成SSH
ssh-keygen -t ed25519 -C "[email protected]"
如果你使用的是不支持Ed25519算法的旧系统, 请使用以下命令:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
注意
这里的[email protected]只是生成的sshkey的名称, 并不约束或要求具体命名为某个邮箱。
现网的大部分教程均讲解的使用邮箱生成, 其一开始的初衷仅仅是为了便于辨识所以使用了邮箱。
3.1 测试连通性
在Git仓库托管处 (GitHub、GitLab或Gitee等) 设置好刚才生成的公钥, 测试连通性:
ssh -T [email protected]
or
ssh -T [email protected]
or
ssh -T [email protected]
4 其他设置
4.1 行尾结束符
行尾结束符, 即EOL(End of Line)。
Linux和MacOS使用LF的系统, 设置为input
:
git config --global core.autocrlf input
Windows这个使用CRLF的, 设置为true
:
git config --global core.autocrlf true
设置文件名大小写敏感:
git config --global core.ignorecase false
设置默认分支:
git config --global init.defaultBranch master
输入错误命令时发出提示, 并等待3秒:
git config --global help.autocorrect 30
4.2 端口号
由于有些学校、企业、机场会屏蔽SSH默认端口号22, 可以修改~/.ssh/config
文件以指定端口号, 比如改用443端口:
# Github
Host github.com
HostName ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github/id_ed25519
Port 443
User git
# Github Gist
Host gist.github.com
HostName ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github/id_ed25519
Port 443
User git
# Gitlab
Host gitlab.com
HostName altssh.gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab/id_ed25519
Port 443
User git