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://[email protected]/itstarting/jtwissandra.git
Password:
error: error setting certificate verify locations:
  CAfile: /bin/curl-ca-bundle.crt
  CApath: none
 while accessing https://[email protected]/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://[email protected]/itstarting/jtwissandra.git

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

你可能感兴趣的:(Git,Github,https,proxy,杂项)