跳转至

配置

git config

  • git config --[local | global | system] xxx.xxx=xxx
  • 配置文件是toml文件格式
  • 配置等级(小的屏蔽大的)
    • --local(项目级别,不写默认是local).git/config
    • --global(当前主机用户), File Path=%HOME%/.gitconfig
    • --system(所有用户)File Path=%GIT_HOME%/etc/gitconfig
  • git config [options...]
    • --addname [value-pattern]添加,可以有多个name,且值可以相同/不同
    • -l, --list显示所有配置
    • --get | --get-all name <value-pattern>根据name、name和value-pattern获取value
    • --get-regexp name-regex [value-pattern]name是正则表达式
    • --unset | --unset-all name [value-pattern]删除指定的name、name和value-pattern
    • --replace-all name new-value [value-pattern]修改指定name、name和value-pattern的value
    • -e, --edit使用编辑器进行编辑

普通配置

## 用户信息
[user]
    name = liruohrh
    email = 2372221537@qq.com
[credential "https://gitee.com"]
## generic: 会将 Gitee 的凭证(用户名 / 密码或 token)存储在系统默认的凭证存储中
    provider = generic
[safe]
  # 不信任则不能执行git命令
    directory = *
[core]
  # 控制路径名中特殊字符的引用方式
    quotepath = true
  # true: 提交时转换为 LF,检出时转换为 CRLF(windows)
  # input:仅在提交时转为LF, 检出时不转换(unix)
    autocrlf = true
  # 比如在--amend时未指定-m时会调用的工具来写message
    editor = 'C:\\Users\\Windows\\AppData\\Local\\Programs\\cursor\\resources\\app\\bin\\cursor' --wait

## 自动替换https为ssh
[url "git@gitee.com:"]
    insteadOf = https://gitee.com/
[difftool "sourcetree"]
    cmd = "'' "
[mergetool "sourcetree"]
    cmd = "'' "
    trustExitCode = false
    keepBackup = false

代理

  • git会根据url判断使用http请求还是ssh请求,代理git有自己的配置,也可以使用默认工具(curl、ssh)的配置

http代理

  • https.https://domain.proxy= && http.https://domain.proxy=
  • 或者环境变量http_proxy、https_proxy(https就要这个)
    \#为特定url进行代理
    [http "https://github.com"] 
      proxy = 127.0.0.1:7890
    [https "https://github.com"] 
      proxy = 127.0.0.1:7890
    

ssh代理

\#全局代理配置就用Host *,否则单独用ProxyCommand,nc默认socks5代理
Host *
  ProxyCommand nc -x 127.0.0.1:7890 %h %p
  # mac 上可能配置代理环境变量即可,配置这个+代理环境变量会导致无法连接
Host github.com
    User git
    Hostname github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/github_macmini

## github提供的2种选择,要么默认的22(ssh),要么443(https),因为22作为ssh可能被所在网络禁用
Host github.com
    User git
    Hostname ssh.github.com
    Port 443
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/github_macmini