主题
Git
下载 & 安装
- Git 下载链接
- 部分安装选项说明:
- 勾选
Add a Git Bash Profile to Windows Terminal
:将Git Bash
添加到Windows Terminal
中。 Windows Explorer Internal
中的Git Bash
和Git GUI
选项可根据需要选择是否勾选。
- 勾选
常见配置
提示
配置文件路径:~/.gitconfig
查看配置
bash
git config --global --list # 查看所有
git config --global user.name # 查看某个(如:用户名)
基本信息配置
用户名、邮箱 这些基本信息配置是必须的!
bash
git config --global user.name "VfanLee"
git config --global user.email "fanfanfafafa@gmail.com"
配置代理
可根据情况进行局部/全局代理
bash
# 设置代理
git config --global http.proxy http://127.0.0.1:10808
git config --global https.proxy https://127.0.0.1:10808
# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
其他常用配置
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
配置 SSH
生成 SSH 密钥,
bashssh-keygen -t rsa -b 4096 -C "github_key"
紧接之后三次回车。
成功执行后,会生成
~/.ssh
文件夹,包含公钥id_rsa.pub
、私钥id_rsa
等文件:bash├── id_rsa # 私钥 └── id_rsa.pub # 公钥
将公钥添加至
GitHub
中。操作路径:
Settings -> SSH and GPG keys -> New SSH key
克隆测试
配置好 ssh 后,克隆的项目地址就不要选择 https 了,选择 ssh 即可,这样就不用手动登录了。
bashgit clone git@github.com:VfanLee/blog.git
ssh 首次连接需要确认,yes 即可。
SSH 代理(非必须)
GitHub SSH 直连访问可能会比较慢,可以为 SSH 配置代理。
编辑
~/.ssh/config
文件bashvi ~/.ssh/config
添加如下配置:
bashHost github.com User git ProxyCommand nc -X 5 -x 192.168.1.10:10808 %h %p
参数说明
-X 5
:指定使用 SOCKS5 代理-x 192.168.1.10:10808
:指定代理地址
连接测试
bashssh -T git@github.com
如果返回如下结果说明成功:
bashHi VfanLee! You've successfully authenticated, but GitHub does not provide shell access.