Ubuntu git clone 错误gnutls_handshake() failed: Handshake failed的解决办法

Ubuntu18.04LTS 自带的git在clone的时候经常出现 ```
failed: fatal: unable to access https://github.com/pdelab/dune-pdelab-howto.git/:
gnutls_handshake() failed: Handshake failed。这是由于Ubuntu中的git使用的是gnutls做安全连接,所以解决办法是我们用openssl替换gnutls。步骤如下:

  1. 卸载Ubuntu自带的git:
sudo apt-get remove git
sudo apt-get remove --auto-remove git
sudo apt-get purge git
sudo apt-get purge --auto-remove git


#!/usr/bin/env bash
set -e

# Gather command line options
for i in “$@”; do
case $i in
-skiptests|–skip-tests) # Skip tests portion of the build
-d=|–build-dir=) # Specify the directory to use for the build
-skipinstall|–skip-install) # Skip dpkg install
#TODO Maybe define a help section?

# Use the specified build directory, or create a unique temporary directory
BUILDDIR=${BUILDDIR:-$(mktemp -d)}
mkdir -p “${BUILDDIR}”
cd “${BUILDDIR}”

# Download the source tarball from GitHub
sudo apt update
sudo apt install curl -y
git_tarball_url=“https://www.github.com$(curl ‘Tags · git/git · GitHub’ | grep -o “/git/git/archive/refs/tags/v2…*.tar.gz” | sort -r | head -1 | tr -d ‘\n’)”
echo “DOWNLOADING FROM: ${git_tarball_url}”
curl -L --retry 5 “${git_tarball_url}” --output “git-source.tar.gz”
tar -xf “git-source.tar.gz” --strip 1

# Source dependencies
# Don’t use gnutls, this is the problem package.
sudo apt remove --purge libcurl4-gnutls-dev -y || true
# Using apt-get for these commands, they’re not supported with the apt alias on 14.04 (but they may be on later systems)
sudo apt-get autoremove -y
sudo apt-get autoclean
# Meta-things for building on the end-user’s machine
sudo apt install build-essential autoconf dh-autoreconf -y
# Things for the git itself
sudo apt install libcurl4-openssl-dev tcl-dev gettext asciidoc -y
sudo apt install libexpat1-dev libz-dev -y

# Build it!
make configure
# --prefix=/usr
# Set the prefix based on this decision tree: https://i.stack.imgur.com/BlpRb.png
# Not OS related, is software, not from package manager, has dependencies, and built from source => /usr
# --with-openssl
# Running ripgrep on configure shows that --with-openssl is set by default. Since this could change in the
# future we do it explicitly
./configure --prefix=/usr --with-openssl
if [[ “${SKIPTESTS}” != “YES” ]]; then
make test

# Install
if [[ “${SKIPINSTALL}” != “YES” ]]; then
# If you have an apt managed version of git, remove it
if sudo apt remove --purge git -y; then
sudo apt-get autoremove -y
sudo apt-get autoclean
# Install the version we just built
sudo make install #install-doc install-html install-info
echo “Make sure to refresh your shell!”
bash -c ‘echo “$(which git) ($(git --version))”’

保存成.sh文件后,运行./compile-git-with-openssl.sh,等待编译过程就可以了,如果过程中出现:env: bash\r: No such file or directory错误,是因为Windows-style \r\n 行结尾,而不是 \n-only 行结尾的bash期望。运行sed $‘s/\r$//’ ./compile-git-with-openssl.sh > ./compile-git-with-openssl.Unix.sh即可替换windows字符。