主题
Git
下载 & 安装
- 下载 Git
- 部分安装选项说明:
Add a Git Bash Profile to Windows Terminal勾选的话,会将
Git Bash添加到Windows Terminal中。Windows Explorer Internal如果已经集成到
Windows Terminal中,可以不勾选Git Bash和Git GUI,右键菜单更简洁。
git 配置
配置文件路径:~/.gitconfig
查看配置:
bash
git config --global --list # 查看所有
git config --global user.name # 查看某个(如:用户名)其他常用配置:
bash
# 忽略大小写,默认值 true
git config --global core.ignoreCase false
# 忽略文件权限变化,默认值 true
git config --global core.filemode false
# eol
git config --global core.autocrlf false
git config --global core.eol lf基本配置
bash
git config --global user.name "example"
git config --global user.email "example@mail.com"SSH
ssh-keygen
-t:指定密钥类型。-C:添加注释。-f:(可选)指定密钥文件的保存路径和名称。
配置 SSH
生成 SSH Key:
bashssh-keygen -t ed25519 -C "key_name" # 兼容旧版本 # ssh-keygen -t rsa -b 4096 -C "key_name"紧接之后三次回车。
成功执行后,会生成
~/.ssh文件夹,包含公钥id_*.pub、私钥id_*,例如:bash├── id_rsa # 私钥 └── id_rsa.pub # 公钥将公钥内容复制到
GitHub中。操作路径:
Settings -> SSH and GPG keys -> New SSH key克隆测试
配置好 ssh 后,以后克隆仓库使用 ssh 地址,例如:
bashgit clone git@github.com:example/repo.git
SSH 代理
安装
corkscrew:bashsudo apt update sudo apt install -y corkscrew编辑
~/.ssh/config(示例:让 git@github.com 默认走代理)bashHost github.com HostName ssh.github.com Port 443 User git IdentityFile ~/.ssh/id_ed25519 IdentitiesOnly yes ProxyCommand corkscrew 192.168.1.8 7897 %h %p连接测试
bashssh -T git@github.com如果返回如下结果说明成功:
bashHi VfanLee! You've successfully authenticated, but GitHub does not provide shell access.
配置多个 SSH Key
生成多个 SSH Key:
bash# 例如:个人 ssh-keygen -t ed25519 -C "key_name" -f ~/.ssh/id_ed25519_personal # 例如:工作 ssh-keygen -t ed25519 -C "key_name" -f ~/.ssh/id_ed25519_work配置
~/.ssh/configbashHost github.com HostName ssh.github.com Port 443 User git IdentityFile ~/.ssh/id_ed25519 IdentitiesOnly yes ProxyCommand corkscrew 192.168.1.8 7897 %h %p Host codeup.aliyun.com HostName codeup.aliyun.com Port 22 User git IdentityFile ~/.ssh/id_ed25519_work IdentitiesOnly yes由于确保每个 git 账号用户名和邮箱不同,需要额外配置 git:
【方法一】在每个仓库单独配置:
bashgit config user.name "your-name" git config user.email "your-eexample@mail.com"【方法二】通过
~/.gitconfig配置:bash[user] name = example email = example@mail.com [includeIf "gitdir:~/work/**"] path = ~/.gitconfig-workbash[user] name = user-name-work email = user-email@work.com
HTTP 代理
提示
可直接使用 bash 的环境变量,而无需配置 git。
设置代理
bash
git config --global http.proxy http://127.0.0.1:7897
git config --global https.proxy https://127.0.0.1:7897取消代理
bash
git config --global --unset http.proxy
git config --global --unset https.proxy