Git push via proxy + https

Git push 默认用git协议,通常情况下大家都可以忽略,透明使用。


然而很多公司需要设置代理,且禁用了一些端口,常见的错误类似于:

bright_zheng@BRIGHT-ZHENG /c/projects_learning/learning-jtwissandra (master)
$ git push -u origin master
ssh: connect to host github.com port 22: Bad file number
fatal: The remote end hung up unexpectedly

导致无法同步到服务端。


此时就需要考虑使用https来push。

以Github + Windows XP设置为例,一般步骤如下:

1. 进入Git Bash,生成ssh证书

$ ssh-keygen 


2. 把生成的key拷贝到当前用户的.ssh下,比如C:\Documents and Settings\bright_zheng\.ssh


3. 拷贝并保持pub的string到github里


4. 设置必要的参数,如http_proxy, user, email等:

$ git config --global http.proxy=yourproxyserver:theport

$ git config --global user.name "Bright Zheng"

$ git config --global user.email youremail@xxx


5. 设置好curl的证书

如果看到这样的错误:

$ git push https://itstarting@github.com/itstarting/jtwissandra.git
Password:
error: error setting certificate verify locations:
  CAfile: /bin/curl-ca-bundle.crt
  CApath: none
 while accessing https://itstarting@github.com/itstarting/jtwissandra.git/info/refs


fatal: HTTP request failed


那需要设置好curl的证书,让其能找到

git config --system http.sslcainfo C:/tools/Git/bin/curl-ca-bundle.crt


6. 在完成必要的commit后,push吧:

git push https://itstarting@github.com/itstarting/jtwissandra.git

提示你输入密码,键入ssh-keygen时你输入的密码即可同步到Github了。


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值