git://协议被公司阻止,我该如何解决? [英] git:// protocol blocked by company, how can I get around that?
问题描述
尝试像 git clone git://github.com/ry/node.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)
但是,通过 HTTP 克隆工作正常.到目前为止,我已经收集到这是协议的问题,但我正在尝试安装需要命令
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
尝试使用 git://协议并失败.有没有办法改变该命令的工作方式?
which is trying to use the git:// protocol and failing. Is there a way to change how that command will work or something?
推荐答案
如果这是防火墙阻止 git: 协议端口 (9418) 的问题,那么您应该进行更持久的更改,这样您就不必记得为每个 git repo 发出其他帖子建议的命令.
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: 协议的子模块.
The below solution also just works for submodules which might also be using the git: protocol.
由于 git 消息并没有真正立即指向阻止端口 9418 的防火墙,让我们尝试将其诊断为实际问题.
Since the git message doesn't really point immediately to the firewall blocking port 9418, lets try to diagnose this as the actual problem.
参考: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
好的,现在我们已经确定是我们的 git 端口被防火墙阻止了,我们能做些什么呢?继续阅读:)
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 提供了一种使用 git config
.只需发出以下命令:
Git provides a way to rewrite URLs using git config
. Simply issue the following command:
git config --global url."https://".insteadOf git://
现在,就像魔法一样,所有的 git 命令都会将 git://
替换为 https://
Now, as if by magic, all git commands will perform a substitution of git://
to https://
使用以下方法查看您的全局配置:
Take a look at your global configuration using:
git config --list
您将在输出中看到以下行:
You'll see the following line in the output:
url.https://.insteadof=git://
您可以通过查看 ~/.gitconfig
来查看文件的外观,您现在应该看到添加了以下两行:
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://
想要更多控制?
只需在替换中使用更完整/更具体的 URL.例如,要仅让 GitHub URL 使用 https://而不是 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
您可以使用不同的替换多次运行此命令.但是,如果 URL 匹配多个替换,则最长的匹配获胜".每个 URL 只会进行一次替换.
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.
如果您是 Linux 系统管理员,并且您不希望您的用户必须经历上述痛苦,您可以在系统范围内快速更改 git 配置.
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.
只需将以下内容编辑或添加到 /etc/gitconfig
中,您的用户就不必担心以上任何一项:
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屋!