如何让 git 通过代理和 IntelliJ Idea 工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3557731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:31:20  来源:igfitidea点击:

How to get git to work through a proxy and IntelliJ Idea?

gitproxyintellij-idea

提问by maximus

Where to I configure the proxy settings for GIT in IntelliJ Idea? I've gotten the proxy settings working for the plugins, but I just can't find it for GIT; and the help files only mention subversion.

我在哪里可以在 IntelliJ Idea 中为 GIT 配置代理设置?我已经获得了适用于插件的代理设置,但我找不到适用于 GIT 的设置;并且帮助文件只提到颠覆。

Any help is appreciated.

任何帮助表示赞赏。

回答by Colin Hebert

You have to configure proxy for git and not for intelliJ, intelliJ will just call the git command line.

您必须为 git 而不是为 intelliJ 配置代理,intelliJ 只会调用 git 命令行。

git config --global http.proxy yourProxy:portshoud do it.

git config --global http.proxy yourProxy:port应该做。

回答by Peter Tillemans

To be complete I would like to add how to hop over a proxy to get to git server or secured sites using ssh, like for example private github repositories.

为了完整起见,我想添加如何跳过代理以使用 ssh 访问 git 服务器或安全站点,例如私有 github 存储库。

For intellij when using this option, you must select to use the nativessh implementation in Project Settings --> Version Control --> VCSs --> Git --> SSH Executable

对于intellij使用这个选项时,必须在Project Settings --> Version Control --> VCSs --> Git --> SSH Executable中选择使用原生ssh实现

We use a tool called corkscrew. This is available for both CygWin (through setup from the cygwin homepage) and Linux using your favorite packaging tool.

我们使用一种叫做开瓶器的工具。这适用于 CygWin(通过从 cygwin 主页进行设置)和使用您最喜欢的打包工具的 Linux。

For MacOSX I refer to this blogpostto install it on you Mac.

对于 MacOSX,我参考这篇博文在 Mac 上安装它。

The command line is as follows :

命令行如下:

corkscrew <proxyhost> <proxyport> <targethost> <targetport> <authfile>

The proxyhost and proxyport are the coordinates of the https proxy.

proxyhost 和 proxyport 是 https 代理的坐标。

The targethost and targetport is the location of the host to tunnel to.

targethost 和 targetport 是要建立隧道的主机的位置。

The authfile is a textfile with 1 line containing your proxy server username/password separated by a colon

authfile 是一个文本文件,其中 1 行包含您的代理服务器用户名/密码,以冒号分隔

e.g:

例如:

abc:very_secret

Installation for using git:// protocol : usually not needed!

安装使用 git:// 协议:通常不需要!

  • Create a helper script to create the tunnel
  • 创建一个帮助脚本来创建隧道

Create a script ~/bin/gitproxywhich contains :

创建一个脚本~/bin/gitproxy,其中包含:

#!/bin/bash
corkscrew proxy.colo.elex.be 3128 github.com 9148 ~/.ssh/proxy_auth 
  • Create the proxy_auth file in the ~/.ssh/ folder
  • 在 ~/.ssh/ 文件夹中创建 proxy_auth 文件

Make sure it is safe from prying eyes.

确保它不会被窥视。

  • Set an environment variable to define the proxy command for git

    $ export GIT_PROXY_COMMAND=/home/pti/bin/gitproxy

  • 设置环境变量来定义git的代理命令

    $ export GIT_PROXY_COMMAND=/home/pti/bin/gitproxy

You might place this in a section or script sourced from .bashrc which dynamically detects if you are behind the proxy or not. If the variable is not defined then git will work as usual.

你可以把它放在一个来自 .bashrc 的部分或脚本中,它动态检测你是否在代理后面。如果未定义变量,则 git 将照常工作。

  • test it
  • 测试一下

Installation for using "normal" ssh protocol for git communication By adding this to the ~/.ssh/config this trick can be used for normal ssh connections

使用“普通” ssh 协议进行 git 通信的安装通过将其添加到 ~/.ssh/config 这个技巧可以用于普通的 ssh 连接

Host gitproxy HostName github.com Port 22 ProxyCommand corkscrew %h %p ~/.ssh/proxy_auth

主机 gitproxy 主机名 github.com 端口 22 ProxyCommand corkscrew %h %p ~/.ssh/proxy_auth

enjoy!

请享用!

回答by Sultanos

In my case i had to set proxy through MSDOS command line, then it pushed results without 407 error

在我的情况下,我必须通过 MSDOS 命令行设置代理,然后它推送结果而没有 407 错误

SET HTTP_PROXY=http://user:[email protected]:portnumber