HTTPS方式
鼠标右键
待保存clone项目的文件夹,选择git Bash Here
- 输入
git clone 复制的项目地址
,回车。
可能出现下列错误:
$ git clone https://github.com/HongguLiu/MesoNet-Pytorch.git
Cloning into 'MesoNet-Pytorch'...
fatal: unable to access 'https://github.com/HongguLiu/MesoNet-Pytorch.git/': OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 0
解决:
- 终端输入下列命令刷新DNS缓存:
ipconfig /flushdns
- 获取github的ip地址:
nslookup github.com
- 然后通过hosts文件手动映射,Hosts文件在
C:\Windows\System32\drivers\etc\hosts
:
# hosts文件末尾添加
# GitHub mappings
140.82.113.4 github.com
140.82.113.4 www.github.com
例如:
# 原本hosts文件
# Copyright (c) 1993-2009 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# For example:
# 127.0.0.1 localhost
# ...略...
# End of section# 在hosts文件结尾添加,即End of section之后
# 更新后hosts文件
# Copyright (c) 1993-2009 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# For example:
# 127.0.0.1 localhost
# ...略...
# End of section
# GitHub mappings
20.205.243.166 github.com
20.205.243.166 www.github.com
- 保存hosts文件,重新git clone,成功。
SSH方式
- 打开终端,输入
ssh-keygen -t rsa -b 4096 -C "your_email@example.com
回车生成SSH密钥(可ls ~/.ssh
查看是否生成成功) - 将公钥添加到github设置中:github中
settings -> SSH and GPG keys -> New SSH key
保存即可(公钥通常保存在用户主文件夹/.ssh/id_rsa.pub
,用户主文件夹即打开终端对话框初始文件夹,私钥通常保存在用户主文件夹/.ssh/id_rsa
。也可终端输入cat ~/.ssh/id_rsa.pub
查看公钥,cat ~/.ssh/id_rsa
查看私钥) - 终端输入
ssh -T git@github.com
测试SSH连接(如果没有建立连接,删除密钥,重复1-2步)。 - 若连接成功,则终端输入
git clone github复制的SSH地址
即可下载项目到本地。