安装 Git

输入命令:

sudo apt-get install git

配置 Git

配置用户名和邮箱地址:

git config --global user.name "Your Name"
git config --global user.email "email@example.com"

创建SSH Key:

ssh-keygen -t rsa -C "youremail@example.com"

这一步的时候, 如果是使用的 Windows 的话, 请注意不能直接在 cmd 中执行该命令, 会报找不到 ssh-keygen 的错误. 正确的应该是右键选择 Git Bash Here, 然后再执行该命令, 就不会报错了.

此时到主目录查看.ssh目录,里面有id_rsaid_rsa.pub两个文件。id_rsa是私钥,不能泄露出去。id_rsa.pub是公钥,把这个加入到GitHub服务器,然后就可以连接到GitHub了。

使用颜色显示:

git config --global color.ui true

参照:

如果不清楚,可以查看廖雪峰官方网站的相关Git教程:廖雪峰Git教程

排错

ssh: connect to host github.com port 22: Connection timed out

git pullgit push 时候出现以上错误,且无论是本地还是服务器,均出现此错误,所以判断并不是本地网络问题。

解决办法:

vim ~/.ssh/config

# add
Host github.com
  Hostname ssh.github.com
  Port 443

Refer: https://stackoverflow.com/a/52817036/4156036

Comments
Write a Comment