【git加速clone项目+切换远程https/ssh方式】

由于众所周知的原因github上clone项目极慢,时不时还一半就断开连接,这里提供使用国内镜像站的解决方法,完成之后修改remote路径以实现modify和push等操作。

还有一个问题,使用git提交文件push到github,每次都要输入用户名和密码,操作起来很麻烦,其原因是在clone 项目的时候,使用了默认的https方式,而不是ssh方式。

加速clone

目前已知Github国内镜像网站有github.com.cnpmjs.orggit.sdut.me。你可以根据你对这两个网站的访问速度快慢,选择其中一个即可。

接下来只需要在clone某个项目的时候将github.com替换为github.com.cnpmjs.org即可。如下例:

1
git clone https://github.com/user/project

替换为

1
git clone https://github.com.cnpmjs.org/user/project

或者

1
git clone https://git.sdut.me/user/project

之后修改仓库push url:

1
2
3
4
git remote -v #查看当前远程url

>origin https://github.com.cnpmjs.org/user/project (fetch)
>origin https://github.com.cnpmjs.org/user/project (push)
1
2
#修改远程push url
git remote set-url --push origin https://github.com/user/project

再次查看url已经变化,之后即可正常push。

切换远程https/ssh方式

到本地项目文件夹子,打开git bash:

  1. 查看clone地址:git remote -v

  2. 移除https的方式,换成ssh方式:git remote rm origin

  3. 添加新的git方式:git remote add origin git@github.com:user/project

  4. 查看push方式是否修改成功:git remote -v

  5. 重新push一下:git push origin master