If you already have an previous version of Git installed, you can clone the latest version:

git clone https://github.com/git/git.git
cd git

Now, we can actually build git

make

By default Git will be installed onto ~/bin. Now we install it.

make install

If the folder doesn't exist, it will be created. The only thing we need to do now is make sure that ~/bin exists in your $PATH

echo $PATH
  /home/ruben/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin

If it doesn't, you can add it.

nano ~/.bashrc

Replace nano with whichever editor you want. At the end add:

export PATH=/home/<username>/bin:${PATH}

To exit nano

ctrl+o
ctrl+x

 

Note

If you want to change where Git is installed to, for example, maybe /home/ruben/opt, we can substitute the make step with:

make prefix=/home/ruben/opt

Obviously replacing ruben with your username. This should work for everyone:

make prefix=${HOME}/opt

For extra options, there's an INSTALL inside the Git folder.