git:// 协议被公司阻止,我该如何解决?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4891527/
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
git:// protocol blocked by company, how can I get around that?
提问by Robert
Attempting something like git clone git://github.com/ry/node.git
will not work, it results in:
尝试类似的方法是git clone git://github.com/ry/node.git
行不通的,它会导致:
Initialized empty Git repository in /home/robert/node/.git/
github.com[0: 207.97.227.239]: errno=Connection timed out
fatal: unable to connect a socket (Connection timed out)
However, cloning over HTTP works fine. So far I've gathered that it's a problem with the protocol, but I'm trying to install cloud9 which is requiring the command
但是,通过 HTTP 克隆工作正常。到目前为止,我已经收集到这是协议的问题,但我正在尝试安装需要命令的 cloud9
git submodule update --init --recursive
git submodule update --init --recursive
which is trying to use the git:// protocol and failing. Is there a way to change how that command will work or something?
它试图使用 git:// 协议并失败。有没有办法改变该命令的工作方式?
回答by Nathan S. Watson-Haigh
If this is an issue with your firewall blocking the git: protocol port (9418), then you should make a more persistent change so you don't have to remember to issue commands suggested by other posts for every git repo.
如果这是防火墙阻止 git: 协议端口 (9418) 的问题,那么您应该进行更持久的更改,这样您就不必记住为每个 git repo 发出其他帖子建议的命令。
The below solution also just works for submodules which might also be using the git: protocol.
以下解决方案也仅适用于可能也使用 git: 协议的子模块。
Since the git message doesn't really point immediately to the firewall blocking port 9418, lets try to diagnose this as the actual problem.
由于 git 消息并没有真正立即指向阻止端口 9418 的防火墙,让我们尝试将其诊断为实际问题。
Diagnosing the Problem
诊断问题
References: https://superuser.com/q/621870/203918and https://unix.stackexchange.com/q/11756/57414
参考资料:https: //superuser.com/q/621870/203918和https://unix.stackexchange.com/q/11756/57414
There are several tools we can use to determine if the firewall causing our problem - use whichever is installed on your system.
我们可以使用多种工具来确定防火墙是否导致了我们的问题 - 使用系统上安装的任何工具。
# Using nmap
# A state of "filtered" against port 9418 (git) means
# that traffic is being filtered by a firewall
$ nmap github.com -p http,git
Starting Nmap 5.21 ( http://nmap.org ) at 2015-01-21 10:55 ACDT
Nmap scan report for github.com (192.30.252.131)
Host is up (0.24s latency).
PORT STATE SERVICE
80/tcp open http
9418/tcp filtered git
# Using Netcat:
# Returns 0 if the git protocol port IS NOT blocked
# Returns 1 if the git protocol port IS blocked
$ nc github.com 9418 < /dev/null; echo $?
1
# Using CURL
# Returns an exit code of (7) if the git protocol port IS blocked
# Returns no output if the git protocol port IS NOT blocked
$ curl http://github.com:9418
curl: (7) couldn't connect to host
OK, so now we have determined it is our git port being blocked by a firewall, what can we do about it? Read on :)
好的,现在我们已经确定是我们的 git 端口被防火墙阻止了,我们能做些什么呢?继续阅读:)
Basic URL Rewriting
基本的 URL 重写
Git provides a way to rewrite URLs using git config
. Simply issue the following command:
Git 提供了一种使用git config
. 只需发出以下命令:
git config --global url."https://".insteadOf git://
Now, as if by magic, all git commands will perform a substitution of git://
to https://
现在,就像魔法一样,所有 git 命令都将执行git://
to的替换https://
What Changes Did This Command Make?
此命令做了哪些更改?
Take a look at your global configuration using:
使用以下命令查看您的全局配置:
git config --list
You'll see the following line in the output:
您将在输出中看到以下行:
url.https://.insteadof=git://
You can see how this looks on file, by taking a peek at ~/.gitconfig
where you should now see that the following two lines have been added:
您可以通过查看~/.gitconfig
现在应该看到添加了以下两行的位置来查看文件中的外观:
[url "https://"]
insteadOf = git://
Want More Control?
想要更多控制?
Simply use a more complete/specific URL in the replacement. For example, to only have GitHub URLs use https:// instead of git://, you could use something like:
只需在替换中使用更完整/特定的 URL。例如,要仅让 GitHub URL 使用 https:// 而不是 git://,您可以使用以下内容:
git config --global url."https://github".insteadOf git://github
You can run this command multiple times using different replacements. However, in the event that a URL matches multiple replacements, the longest match "wins". Only a single replacement will be made per URL.
您可以使用不同的替换多次运行此命令。但是,如果 URL 匹配多个替换,则最长的匹配“获胜”。每个 URL 只会进行一次替换。
System-Wide Changes for Sysadmins
系统管理员的系统范围更改
If you're a Linux Sysadmin and you don't want your users to have to go through the above pains you can make a quick system-wide git configuration change.
如果您是 Linux 系统管理员,并且不希望您的用户经历上述痛苦,您可以快速更改系统范围的 git 配置。
Simply edit or add the following contents to /etc/gitconfig
and voila your users don't have to worry about any of the above:
只需编辑或添加以下内容,/etc/gitconfig
您的用户就不必担心上述任何内容:
[url "https://"]
insteadOf = git://
回答by Cascabel
Github provides http(s) access too, which is much less likely to be blocked by your company. To tell the submodule to use that, you can do this:
Github 也提供 http(s) 访问,这不太可能被贵公司阻止。要告诉子模块使用它,您可以这样做:
git submodule init
git config submodule.<name>.url https://github.com/...
git submodule update
This is actually exactly why init and update are separate commands - you can init, customize locations, then update. update --init
is just a shortcut for when you don'ot need to customize any URLs.
这实际上正是 init 和 update 是单独命令的原因——您可以初始化、自定义位置,然后更新。update --init
只是当您不需要自定义任何 URL 时的快捷方式。
For anyone else who happens across this, you could of course also use an ssh URL (if your company blocks git:// but not ssh), but in this case the OP presumably doesn't have SSH access to the remote repo.
对于遇到这种情况的任何其他人,您当然也可以使用 ssh URL(如果您的公司阻止 git:// 但不阻止 ssh),但在这种情况下,OP 可能没有对远程存储库的 SSH 访问权限。
回答by elpddev
Another option which not involving touching git config is to change the ssh settings to use port 443 instead of the regular 22 port.
另一个不涉及 git config 的选项是更改 ssh 设置以使用端口 443 而不是常规的 22 端口。
Reference: Using SSH over the HTTPS port
From that article:
从那篇文章:
edit the file at ~/.ssh/config, and add this section:
Host github.com
Hostname ssh.github.com
Port 443
Afterward, I was able to successfully git push to Github. At home you can change back ssh config to the way it was if you want.
之后,我能够成功地 git push 到 Github。在家里,您可以根据需要将 ssh 配置改回原样。
回答by K M Rakibul Islam
I was also having the same issue for a while. Then I tried changing the git config using the suggested command:
我也有一段时间遇到同样的问题。然后我尝试使用建议的命令更改 git 配置:
git config --global url."https://".insteadOf git://
which unfortunately did not do the trick for me. I was still having the same problem!
不幸的是,这对我没有帮助。我仍然遇到同样的问题!
What actually solved my problem at last is, I have reset the remote url of my repository again using the following command:
最后真正解决了我的问题的是,我使用以下命令再次重置了我的存储库的远程 url:
git remote set-url origin https://github.com/<my_user_name>/<my_repo_name>.git
which was previously like this:
以前是这样的:
git remote set-url origin [email protected]:<my_user_name>/<my_repo_name>.git
After setting the remote url using https://
instead of [email protected]
the problem was resolved for me.
使用https://
而不是设置远程 url 后[email protected]
,我解决了问题。
回答by jhiller
Expanding on Nathan's answer above, you can also try the ssh protocol if your corporate firewall is interfering with https. In my case the firewall was blocking git protocol, re-issuing ssl certificates for https and this was breaking bower for me, even with the strict-ssl option turned off. You can do a similar url rewrite for ssh, and create a ssh key/pair as described on github.
扩展上面 Nathan 的回答,如果您的公司防火墙干扰 https,您还可以尝试 ssh 协议。在我的情况下,防火墙阻止了 git 协议,为 https 重新颁发 ssl 证书,这对我来说破坏了 bower,即使关闭了 strict-ssl 选项。您可以对 ssh 进行类似的 url 重写,并按照 github 上的描述创建一个 ssh 密钥/对。
git config --global url."ssh://[email protected]".insteadOf git://github.com
You would also have to turn on the ssh-agentfor your git install.
您还必须为您的 git 安装打开 ssh-agent。
回答by fmo
it's because the GIT adresse for the node server has changed you have to enter now:
这是因为节点服务器的 GIT 地址已更改,您现在必须输入:
git clone https://github.com/joyent/node
git 克隆https://github.com/joyent/node
good luck
祝你好运
回答by Menios
Introduction
介绍
I will add here my own approach ( which is not required if you have a publicly accessible git repository that supports https).
我将在这里添加我自己的方法(如果您有一个支持 https 的可公开访问的 git 存储库,则不需要)。
I work at a company where the git repository is only accessible from inside the company. But I also work from home.
我在一家只能从公司内部访问 git 存储库的公司工作。但我也在家工作。
How do I push to the company repository from home?
如何从家里推送到公司存储库?
I have created a repository with a folder on my google drive. Except for git, and https, you can include repositories as paths.
我在我的谷歌驱动器上创建了一个带有文件夹的存储库。除了 git 和 https,您可以将存储库包含为路径。
So, instead of pushing to origin I push to "gDrive". This causes the folder to synch from my home workstation to google drive, and then my work computer pulls the changes. Additionally, since sometimes files in the ".git" directory don't synch, I rename the folder temporarily from e.g. "trunk" to "trunk2". This forces both home and work computers to be 100% synched with google drive.
因此,我没有推送到原点,而是推送到“gDrive”。这会导致文件夹从我的家庭工作站同步到谷歌驱动器,然后我的工作计算机提取更改。此外,由于有时“.git”目录中的文件不同步,我将文件夹从例如“trunk”临时重命名为“trunk2”。这迫使家庭和工作计算机与谷歌驱动器 100% 同步。
I then log-on to my work computer either through checkpoint-vpn remote ( or teamviewer) and push my updates to the work git repository.
然后我通过 checkpoint-vpn remote(或 teamviewer)登录到我的工作计算机并将我的更新推送到工作 git 存储库。
Additionally, the process would work vice-versa for pushing to a git repository outside the company that is blocked.
此外,该过程将反之亦然,用于推送到被阻止的公司外部的 git 存储库。
- Push from workstation git repo to folder in google drive.
- Force 100% synch by temporarily renaming project directory in gDrive.
- Access home computer through some kind of remote and push changes.
- 从工作站 git repo 推送到谷歌驱动器中的文件夹。
- 通过临时重命名 gDrive 中的项目目录来强制 100% 同步。
- 通过某种远程访问家庭计算机并推送更改。