Git基础教程
第一次运行Git
在安装完Git后,我们需要进行一些配置。
下面的命令将设置你的用户信息和邮件地址,将yourUserName替换为你的用户名,[email protected]替换为你的电子邮件地址
git config --global user.name "yourUserName"
git config --global user.email [email protected]
举一个Github账号示例,例如Github用户名为123,电子邮件地址为[email protected],则应该输入下面的命令git config --global user.name 123
git config --global user.email [email protected]
接着,如果你拥有一个Github账号和一个Github私密仓库,想要将仓库克隆到本地则需要创建一个SSH密钥。
将下面的[email protected]替换为注册github的邮箱
ssh-keygen -t ed25519 -C "[email protected]"
当你被提示选择保存密钥的文件时,按 Enter 接受默认文件位置。
> Enter a file in which to save the key (/home/YOU/.ssh/id_ed25519_sk):[Press enter]
当你被提示输入密码时,按 Enter 即可跳过设置 ssh key 密码> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]
接着我们需要查看一下公钥,在Linux下输入下面的命令查看公钥文件名,输出类似于 xxx.pub的文件,就是这个.pub后缀的文件就是娘车公钥ls ~/.ssh
接着我们复制一下公钥,假设你的公钥文件名为 id_ed25519.pubcat ~/.ssh/id_ed25519.pub
输出的内容就是你的公钥了接着将公钥复制后,进入到Github官网,登录后点击右上角的头像,点击Settings,接着在左侧找到SSH and GPG keys选项,在SSH keys右侧点击New SSH Key,接着在Key处粘贴你的公钥,Title处填写想要命名的名字即可,例如电脑型号,用途等等。
有关git代理
全局设置(不推荐)
使用http代理
1 | git config --global http.proxy http://127.0.0.1:1080 |
使用socks5代理
1 | git config --global http.proxy socks5://127.0.0.1:1080 |
只对Github代理(推荐)
使用socks5代理(推荐)
1 | git config --global http.https://github.com.proxy socks5://127.0.0.1:1080 |
使用http代理(不推荐)
1 | git config --global http.https://github.com.proxy http://127.0.0.1:1080 |
取消代理
当你不需要使用代理时,可以取消之前设置的代理。
1 | git config --global --unset http.proxy git config --global --unset https.proxy |
查看代理
1 | git config --global --get http.proxy |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 NineHeaven!


