在公司这样的局域网环境中,向要走网络必须走HTTP代理出去。不能直接访问外面的服务,因此这样安全了些,可是也提供了不便的地方。所以须要设置一些代理才能使用。html

经常使用的代理有:git

  • HTTP、HTTPS代理 许多程序支持http代理
  • SOCKS代理 不是全部的程序都支持socks代理,可是经常使用的软件都支持

github上的仓库支持ssh、https、git三种协议的chekout(clone)操做。github

生成SSH Key

参考http://www.chenyudong.com/archives/ssh-using-private-public-key-no-password.html进行SSH密钥的生产web

git使用http访问

github上能够使用https进行访问。shell

1
$ git config --global http.proxy http: //web-proxy .oa.com:8080

可是这样能够clone了。可是若是要push代码,那就麻烦了。每次都须要输入密码。vim

git使用ssh进行访问

使用ssh协议不只能够访问github,还能够访问咱们本身的git私有仓库,能够参考文章经过SSH建立私有git仓库安全

首先,Windows用户先下载一个mysgit客户端,下个portable版的就行了,https://github.com/msysgit/msysgit/releases里面有git程序。Linux用户跳过。bash

第二步,配置ssh。Windows用户运行mysgit中的git-bash.bat来启动终端。编辑vim ~/.ssh/config ,将下面的内容写入到文件中网络

1
2
3
4
Host github.com *.github.com
     ProxyCommand connect -H web-proxy.oa.com:8080 %h %p   #设置代理
     IdentityFile ~/. ssh /privatekey/id_rsa .github
     User git

ProxyCommand说明了设置代理,其中connect是个程序,Windows用户下载了mysgit,里面有这个程序,Linux用户可能没有,须要安装sudo apt-get install connect-proxyssh

若是你使用corkscrew,那么解压缩附件,把corkscrew.exe和cygwin1.dll拷贝到mysgit的bin目录中。附:corkscrew.zip

第三步,测试

1
2
ssh -T git@github.com
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

 

转自:http://www.chenyudong.com/archives/use-git-or-github-in-company-local-net.html