git:// protocol blocked by company, how can I get around that?

GitGithub

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

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:

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.

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.

Solution 3 - Git

Another option which not involving touching git config is to change the ssh settings to use port 443 instead of the regular 22 port.

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.

Solution 4 - Git

I was also having the same issue for a while. Then I tried changing the git config using the suggested command:

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:

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 git@github.com:<my_user_name>/<my_repo_name>.git

After setting the remote url using https:// instead of [email protected] the problem was resolved for me.

Solution 5 - Git

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.

 git config --global url."ssh://[email protected]".insteadOf git://github.com

You would also have to turn on the ssh-agent for your git install.

Solution 6 - Git

it's because the GIT adresse for the node server has changed you have to enter now:

git clone https://github.com/joyent/node

good luck

Solution 7 - Git

Introduction

I will add here my own approach ( which is not required if you have a publicly accessible git repository that supports https).

I work at a company where the git repository is only accessible from inside the company. But I also work from home.

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.

enter image description here

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.

I then log-on to my work computer either through checkpoint-vpn remote ( or teamviewer) and push my updates to the work git repository.

Additionally, the process would work vice-versa for pushing to a git repository outside the company that is blocked.

  1. Push from workstation git repo to folder in google drive.
  2. Force 100% synch by temporarily renaming project directory in gDrive.
  3. Access home computer through some kind of remote and push changes.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobertView Question on Stackoverflow
Solution 1 - GitNathan S. Watson-HaighView Answer on Stackoverflow
Solution 2 - GitCascabelView Answer on Stackoverflow
Solution 3 - GitelpddevView Answer on Stackoverflow
Solution 4 - GitK M Rakibul IslamView Answer on Stackoverflow
Solution 5 - GitjhillerView Answer on Stackoverflow
Solution 6 - GitfmoView Answer on Stackoverflow
Solution 7 - GitMenelaosView Answer on Stackoverflow