git://协议被公司阻止,我该如何解决这个问题? [英] git:// protocol blocked by company, how can I get around that?

查看:152
本文介绍了git://协议被公司阻止,我该如何解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试像> git clone git://github.com/ry/node.git 之类的东西不起作用,它会导致:

 在/home/robert/node/.git/ 
中初始化空的Git存储库github.com [0:207.97.227.239]:errno =连接超时out
fatal:无法连接套接字(连接超时)

但是,克隆HTTP工作正常。到目前为止,我已经认识到这是协议的问题,但我试图安装需要命令的cloud9。

git submodule更新 - 初始化 - 递归



正在尝试使用git://协议并失败。有没有办法改变命令的工作方式或者什么? 解决方案

如果这是你的防火墙阻止git的问题:协议端口(9418),那么你应该做一个更持久的改变,所以你不必记得为每个git repo发布其他帖子建议的命令。



以下解决方案也适用于也可能使用git:protocol的子模块。



由于git消息并未真正指向防火墙阻止端口9418,我们可以尝试将此诊断为实际问题。



诊断问题



参考文献:https://superuser.com/q/621870/203918 https://unix.stackexchange.com/q/11756/57414



我们可以使用几种工具来确定防火墙导致我们的问题 - 使用任何一个

 #使用nmap 
#针对端口9418(git)的过滤状态意味着流量被防火墙过滤的

$ nmap github.com -p http,git

在2015年开始Nmap 5.21(http://nmap.org) -01-21 10:55 ACDT
github.com的Nmap扫描报告(192.30.252.131)
主机已启动(延迟0.24秒)。
PORT STATE SERVICE
80 / tcp打开http
9418 / tcp过滤git

#使用Netcat:
#如果git协议端口为IS,则返回0不被阻止
#如果git协议端口被阻塞,则返回1
$ nc github.com 9418<的/ dev / null的; echo $?
1

#使用CURL
#如果git协议端口被阻塞,返回(7)的退出代码
#如果git协议端口是IS,则返回无输出不会阻止
$ curl http://github.com:9418
curl:(7)无法连接到主机

好的,现在我们已经确定它是我们的git端口被防火墙阻止了,我们能做些什么呢? )



基本URL重写



Git提供了一种使用 git config 。只需发出以下命令:

  git config --global url。https://.insteadOf git:// 

现在,就像通过魔术一样,所有的git命令都会执行 git :// https://



这个命令做了什么改变?



使用以下命令查看您的全局配置:

  git config --list 

您将在输出中看到以下行:

  url.https://.insteadof=git:// 

您可以通过查看〜/ .gitconfig 来了解它在文件中的显示方式,您应该看到以下两行已被添加:

  [urlhttps://] 
insteadOf = git://



想要更多控制权?



只需使用更完整/替换中的特定网址。例如,要仅让GitHub URL使用https://而不是git://,则可以使用以下内容:

  git config --global url。https:// github.insteadOf git:// github 

您可以使用不同的替换多次运行此命令。但是,如果某个网址匹配多个替换项,则最长匹配项为胜出。



系统管理员对系统管理员的更改



如果你是一个Linux系统管理员,你不希望你的用户必须经历上述的痛苦,你可以做一个快速的系统范围的git配置更改。



只需编辑或添加将以下内容添加到 / etc / gitconfig 中,并且您的用户不必担心以上任何内容:

  [urlhttps://] 
insteadOf = git://


Attempting something like git clone git://github.com/ry/node.git will not work, it results in:

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

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?

解决方案

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.

The below solution also just works for submodules which might also be using the git: protocol.

Since the git message doesn't really point immediately to the firewall blocking port 9418, lets try to diagnose this as the actual problem.

Diagnosing the Problem

References: https://superuser.com/q/621870/203918 and 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 :)

Basic URL Rewriting

Git provides a way to rewrite URLs using git config. Simply issue the following command:

git config --global url."https://".insteadOf git://

Now, as if by magic, all git commands will perform a substitution of 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:

[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:

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.

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.

Simply edit or add the following contents to /etc/gitconfig and voila your users don't have to worry about any of the above:

[url "https://"]
    insteadOf = git://

这篇关于git://协议被公司阻止,我该如何解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆