Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I try to connect to any HTTPS server with git, it gives the following error:

error: gnutls_handshake() failed: A TLS packet with unexpected length was received. while accessing ...
fatal: HTTP request failed

I think that maybe some packages that are related to gnutls_handshake have been broken. So, I want to reinstall those.

Which packages can be related to these errors? Or how do I fix this kind of error?

share|improve this question
This other question might help. – Christopher Sep 12 '12 at 12:53

Got reason of the problem, it was gnutls package. It's working weird behind a proxy. But openssl is working fine even in weak network. So workaround is that we should compile git with openssl. To do this, run the following commands:

sudo apt-get update
sudo apt-get install build-essential fakeroot dpkg-dev libcurl4-openssl-dev
sudo apt-get build-dep git
mkdir ~/git-openssl
cd ~/git-openssl
apt-get source git
dpkg-source -x git_1.7.9.5-1.dsc
cd git-

(Remember to replace with the actual version of git in your system.)

Then, edit debian/control file (run the command: gksu gedit debian/control) and replace all instances of libcurl4-gnutls-dev with libcurl4-openssl-dev.

Then build the package (if it's failing on test, you can remove the line TEST=test from the file debian/rules):

sudo dpkg-buildpackage -rfakeroot -b

Install new package:

i386: sudo dpkg -i ../git_1.7.9.5-1_i386.deb

x86_64: sudo dpkg -i ../git_1.7.9.5-1_amd64.deb

Inspired from here:

share|improve this answer
Had this same issue after upgrading to Ubuntu 14.04. This solution worked great! – vertti Apr 23 '14 at 10:34
Worked with Linux Mint 16, you have to go to "Software Sources" and enable sources on official repositories. You must also uninstall libcurl4-gnutls-dev and replace by libcurl4-openssl-dev prior to compiling. – Guillaume Perrot Jun 12 '14 at 9:05
Might help the wondering minds. If you're using 'repo' to download a repository (say android source code) and come across the gnutls-handshake problem, @Nyambaa's answer works. Repo is a script which depends on Git, so you should be good. Worked like magic on my Ubuntu 14.04 lts – Rexford Nov 16 '14 at 3:11
This also worked to solve my Android repo sync problem that was resulting in error: RPC failed; result=56, HTTP code = 200. – Xargs Jan 24 '15 at 1:20
the tests in the build step take a really long time. if you trust the git maintainers, I highly suggest following the instructions above to skip them by removing the TEST=test line from debian/rules. – Eli Albert Sep 30 '15 at 16:01

protected by Community Oct 30 '13 at 17:17

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.