How to upgrade to latest git on debian 7?

I have installed git through apt-get on debian 7 which gives me:

# git --version
git version 1.7.10.4

I would like to ugrade to the latests version of git. I have tried:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git

But that gives the following errors:

Fetched 6,944 B in 0s (10.1 kB/s)
W: Failed to fetch http://ppa.launchpad.net/git-core/ppa/ubuntu/dists/wheezy/main/source/Sources  404  Not Found

W: Failed to fetch http://ppa.launchpad.net/git-core/ppa/ubuntu/dists/wheezy/main/binary-amd64/Packages  404  Not Found

I have also tried to follow this guide:

http://backports.debian.org/Instructions/

but I still cannot get the latest git, any suggestions?


Solution 1:

Updated 2016-07-27: a wheezy-backports is now available for Git 1.9.1. Instructions still applies to install a more recent version or for Jessie.


When a newer version of a backport package isn't available, you have two options:

  1. Ask the package maintainers to prepare a backport. It's not guaranteed to work but some maintainers are positive about making backports, so I'd just try.

    The maintainers' e-mails could be found there.

  2. Build it yourself from the sources. This could be done two ways:

    • Build "as is" from the source tarball. Should you pick this route, be sure to configure the Git's build system to install everything under ~/git or /opt/git or something like this otherwise later you'll have a great PITA removing what you installed.

      The problem is that the conventional Unix way of installing software by spreading it across the whole filesystem is sensible but only when you have some sort of registry which "knows" which file belongs to which package and vice-versa, and packaging systems such as Debian's do exactly this. If you do "normal" install of a package built from the sources, you in most cases will have no way to uninstall this piece of software later (short of using checkinstall instead of make install, but this really is a last resort). Conversely, if you configure a source package to install everything under a single directory, you will have minor difficulties running the software (its "binary" directories won't be on your $PATH), in exchange uninstalling it later will be a no-brainer — a single rm -rf /path/to/that/dir.

    • Do backporting yourself. This is more involved but in simple cases it might just work so IMO it worth trying.

      Basically you go like this (a link to the .dsc file is taken from the package's page in unstable):

      # apt-get install devscripts
      $ mkdir ~/devel && cd $_
      $ dget http://ftp.de.debian.org/debian/pool/main/g/git/git_2.1.4-2.1.dsc
      $ dpkg-source -x git_2.1.4-2.1.dsc
      $ cd git
      

      Check if you have all the build dependencies satisfied by running:

      $ dpkg-checkbuilddeps
      

      And install everything that tool says is presently missing. Sometimes a package might refer to a version of something too fresh to be available in the distro you're backporting to; in this case it's okay to try to cheat and fix the version of such a package in the debian/control file.

      Now fix up the version of the packages about to be built. The best way to achieve this is to have a tool do the right thing:

      $ dch --bpo
      

      It will add an entry to the debian/changelog file and open your text editor of choice to oversee it. Just close the editor — the version for the packages to be built is taken from the top entry in this file.

      Now let's actually attempt to build:

      $ dpkg-buildpackage -uc -us -b
      

      If you're lucky, at this point you'll have a bunch of shiny new Git .deb packages in .., which you can just install using dpkg -i <packagename> ....

      (Run debuild clean to get rid of the built crud or just remove the git directory completely. You might also want to remove whatever you installed after running dpkg-checkbuilddep.)

      Unfortunately, if building fails for some reason, it takes certain knowledge to attempt to fix but this is out of scope of this discussion.

Solution 2:

You can still use the Git PPA for Ubuntu Precise by telling apt to build from the latest source it finds there. The distributions are similar enough that this should work just fine.

I used it with success on Raspbian (which is based on wheezy) to get packages for armhf, but it should work for any architecture.

First add the GPG key for the PPA:

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E1DF1F24

Add the URL for the source packages to apt:

cat > /etc/apt/sources.list.d/git.list << EOF
deb-src http://ppa.launchpad.net/git-core/ppa/ubuntu precise main
EOF

Update apt:

apt-get update

Install build dependencies:

apt-get build-dep git

Download and build git from source. You may want to do this is a temporary directory, as the build process creates a bit of cruft:

apt-get -b source git

Install the package you just built and clean up (git-core is no longer needed):

dpkg -i git_*.deb git-man_*.deb
dpkg -P git-core