---
title: "Git push via proxy + https"
author: "itstarting"
date: "2012-03-02T14:41:38Z"
tags: []
categories: ["研发管理"]
slug: "git-push-via-proxy-https"
draft: false
lastmod: "2012-03-02T14:41:37Z"
id: 1436321
url: "https://itstarting.iteye.com/blog/1436321"
---

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了。