The Basic Steps
TL;DR – If you are stuck trying to debug git, then here is a step by step process I use to figure out the problems:
- Check permissions of where you are trying to copy
- Ping the server with the repository
- Try a different protocol (git[ssh] <-> https <-> http)
When cloning repositories from git you can use a lot of different syntax. You can clone repositories that are local by providing a local path instead of a network path, and you can use different protocols.
Note: The Git protocol doesn’t use authentication and is generally used for pulling only, and is paired with an HTTPS/SSH protocol for those pushing. The Git transport protocol uses port 9418.
Most IT teams will already be blocking SSH (port 22), and thus just switching to HTTPS (port 443) or HTTP (port 80) will work, as these ports are generally open for web services. If you are using a non-public repository then HTTP will not work.
For more information on Git Protocols see:
Timeouts can occur due to several reasons, some of these are servers being down, missing repositories, overloaded servers, permissions, etc.
A timeout looks like this:
$ git clone email@example.com:user/repo.git Cloning into 'repo'... ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
From here you can set the variable
GIT_TRACE to debug:
$ GIT_TRACE=2 git clone firstname.lastname@example.org:user/repo.git trace: built-in: git 'clone' 'email@example.com:user/repo.git' Cloning into 'repo'... trace: run_command: 'ssh' 'firstname.lastname@example.org' 'git-upload-pack '\''user/repo.git'\''' ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
This doesn’t give us much, but it makes it clear that we are using the ssh protocol and trying to communicate on port 22.
Unable to connect
Unable to connect errors can also occur which look like:
$ git clone git://github.com/user/repo.git Cloning into 'repo'... fatal: unable to connect to github.com: github.com[0: 192.168.1.100]: errno=Connection timed out
Then this is telling you that you couldn’t communicate with the Git server. Make sure you can ping the server (ping github.com). If ping works, then perhaps your ports are not open or you have UPNP disabled on your router (which you should have).
Open any ports you need for protocols you are using – if possible. If you are at work or for some reason cannot forward/open a port, then go ahead and try using the https:// protocol:
git clone https://github.com/user/repo.git
If you are seeing other problems, then try running:
export GIT_SSH_COMMAND="ssh -v" git clone git://github.com/user/repo.git
This will change the Git ssh command to:
ssh -v and it will print verbose messages about the connection (this is just ssh verbose mode).
If you are still stuck, then one of the best things you can do is to enable git debugging:
GIT_CURL_VERBOSE=1 git clone git://github.com/user/repo.git GIT_TRACE=2 git clone git://github.com/user/repo.git
Another problem several people have is trying to make git work through a proxy. One way to do this is to tunnel SSH traffic through a proxy (e.g. proxy host is ‘proxy’ and port is ‘1080’):
# ~/.ssh/config ProxyCommand /usr/bin/nc -X 5 -x proxy:1080 %h %p
Note: Your IT team will probably be able to see all of your SSH activity. You should certainly make sure that you have permission to do this from your IT team before you attempt it.
I like science and writing software.