目录

Git Config

git config有三个级别: systemglobal (用户, 全局生效) 和local (用户, 当前仓库), 优先级为system>global>local, 分别使用--system/global/local参数来指定级别。

  • 查看系统 (system) 的git config:

    shell

    git config --system --list
  • 查看用户全局 (global) 的git config:

    shell

    git config --global --list
  • 查看当前仓库 (local) 的git config:

    shell

    git config --local --list
不使用参数时
如果不使用--system/global/local参数, 直接使用git config --list命令, 则输出system+global+local的git config; 如果当前路径不是git仓库, 则只输出system+global的git config。

shell

git config --global user.name "your_name"
git config --global user.email "[email protected]"

shell

ssh-keygen -t ed25519 -C "[email protected]"

如果你使用的是不支持Ed25519算法的旧系统, 请使用以下命令:

shell

ssh-keygen -t rsa -b 4096 -C "[email protected]"
注意

这里的[email protected]只是生成的sshkey的名称, 并不约束或要求具体命名为某个邮箱。

现网的大部分教程均讲解的使用邮箱生成, 其一开始的初衷仅仅是为了便于辨识所以使用了邮箱。

在Git仓库托管处 (GitHub、GitLab或Gitee等) 设置好刚才生成的公钥, 测试连通性:

行尾结束符, 即EOL(End of Line)。

Linux和MacOS使用LF的系统, 设置为input:

shell

git config --global core.autocrlf input

Windows这个使用CRLF的, 设置为true:

shell

git config --global core.autocrlf true

设置文件名大小写敏感:

shell

git config --global core.ignorecase false

设置默认分支:

shell

git config --global init.defaultBranch master

输入错误命令时发出提示, 并等待3秒:

shell

git config --global help.autocorrect 30

由于有些学校、企业、机场会屏蔽SSH默认端口号22, 可以修改~/.ssh/config文件以指定端口号, 比如改用443端口:

text

# 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