尝试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)
Run Code Online (Sandbox Code Playgroud)
但是,通过HTTP克隆工作正常.到目前为止,我已经收集到这是协议的问题,但我正在尝试安装需要命令的cloud9
git submodule update --init --recursive
它试图使用git://协议并失败.有没有办法改变命令的工作方式?
Nat*_*igh 422
如果这是防火墙阻止git:protocol端口(9418)的问题,那么您应该进行更持久的更改,这样您就不必记住为每个git repo发出其他帖子建议的命令.
以下解决方案也适用于可能也使用git:协议的子模块.
由于git消息并未真正指向防火墙阻塞端口9418,因此我们尝试将其诊断为实际问题.
参考文献:https://superuser.com/q/621870/203918和https://unix.stackexchange.com/q/11756/57414
我们可以使用几种工具来确定防火墙是否导致我们的问题 - 使用系统上安装的任何一个.
# 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
Run Code Online (Sandbox Code Playgroud)
好的,现在我们已经确定我们的git端口被防火墙阻止了,我们能做些什么呢?继续阅读:)
Git提供了一种使用重写URL的方法git config.只需发出以下命令:
git config --global url."https://".insteadOf git://
Run Code Online (Sandbox Code Playgroud)
现在,好像通过魔术,所有git命令将执行替换git://为https://
使用以下方法查看您的全局配置:
git config --list
Run Code Online (Sandbox Code Playgroud)
您将在输出中看到以下行:
url.https://.insteadof=git://
Run Code Online (Sandbox Code Playgroud)
您可以通过查看~/.gitconfig现在应该看到添加以下两行的位置来查看文件的外观:
[url "https://"]
insteadOf = git://
Run Code Online (Sandbox Code Playgroud)
只需在替换中使用更完整/特定的URL.例如,要仅使GitHub URL使用https://而不是git://,您可以使用以下内容:
git config --global url."https://github".insteadOf git://github
Run Code Online (Sandbox Code Playgroud)
您可以使用不同的替换多次运行此命令.但是,如果URL匹配多个替换,则最长匹配"获胜".每个URL只能进行一次替换.
如果您是Linux系统管理员并且不希望用户必须经历上述困难,那么您可以在系统范围内快速进行git配置更改.
只需编辑或添加以下内容即可/etc/gitconfig,您的用户无需担心以上任何内容:
[url "https://"]
insteadOf = git://
Run Code Online (Sandbox Code Playgroud)
Cas*_*bel 29
Github也提供http(s)访问权限,这不太可能被贵公司阻止.要告诉子模块使用它,您可以这样做:
git submodule init
git config submodule.<name>.url https://github.com/...
git submodule update
Run Code Online (Sandbox Code Playgroud)
这实际上就是为什么init和update是单独的命令 - 你可以初始化,自定义位置,然后更新.update --init只是您不需要自定义任何URL的快捷方式.
对于发生这种情况的其他任何人,您当然也可以使用ssh URL(如果您的公司阻止git://但不阻止ssh),但在这种情况下,OP可能没有SSH访问远程仓库.
elp*_*dev 13
另一个不涉及触摸git配置的选项是将ssh设置更改为使用端口443而不是常规22端口.
从那篇文章:
edit the file at ~/.ssh/config, and add this section:
Host github.com
Hostname ssh.github.com
Port 443
Run Code Online (Sandbox Code Playgroud)
之后,我能够成功地向Github推送.在家里,你可以改变ssh配置,如果你想要的话.
我有一段时间也遇到了同样的问题.然后我尝试使用建议的命令更改git配置:
git config --global url."https://".insteadOf git://
Run Code Online (Sandbox Code Playgroud)
不幸的是,这对我来说并没有成功.我还有同样的问题!
实际上最终解决了我的问题的是,我使用以下命令再次重置了我的存储库的远程URL:
git remote set-url origin https://github.com/<my_user_name>/<my_repo_name>.git
Run Code Online (Sandbox Code Playgroud)
以前是这样的:
git remote set-url origin git@github.com:<my_user_name>/<my_repo_name>.git
Run Code Online (Sandbox Code Playgroud)
设置远程网址后使用https://而不是git@git.com问题解决了我.