Installing latest git on Ubuntu with git-subtree support

Recently I found it necessary to join two git repos together while still maintaining history & future ability to split or rejoin them.  Enter the ‘git subtree‘ command.

Because this command is now merged into git-core since 1.7.11, we will need to install the latest git from a PPA.  Note that as of ‘now‘, the latest available package from the PPA we will use is 1.8.0, and it currently installs the subtree script to /usr/share/doc/git/contrib/subtree. However, since the Makefile there expects asciidoc.conf to be in ../../Documentation/asciidoc.conf, we must checkout the source package & make from there.

I am using Ubuntu 12.04.1 LTS here.

Installing latest git-core + git-subtree

First add the PPA, update & upgrade.  Then install git packages that are held back by apt.  Also install asciidoc (optional if you want the manpage).

sudo add-apt-repository ppa:git-core/ppa && sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y install git git-man git-svn asciidoc

Next, install the source package & make git-subtree + manpage:

[ ! -e '~/src/git-core' ] && mkdir -p ~/src/git-core
cd ~/src/git-core && apt-get source git-core
cd ~/src/git-core/git-*/contrib/subtree/
[ -e '/usr/lib/git-core' ] && sed -i -e '/^libexecdir.*/ s|/libexec/|/lib/|' Makefile || echo '/usr/lib/git-core does not exist! Check that your libexec dir exists and reinstall git-subtree'
sudo make prefix=/usr && sudo make prefix=/usr install && sudo make prefix=/usr install-doc

This may not work for you if you’re not using Ubuntu (your prefix or libexec dir may be different).  If in doubt, get git-core from upstream and build it from there, or install the script to $(git --exec-path)/git-subtree and chmod 755 it (see Makefile & INSTALL doc in contrib/subtree).

Now you should be able to use the ‘git subtree‘ command.  For help, run ‘git help subtree‘ or ‘man git-subtree‘.

Some helpful examples of git subtree in use in the wild:

 

 

Update 2012-10-22:  Currently the package for git 1.8.0 from the PPA does not include the git-prompt.sh script.  If you are using the __git_ps1 function in your bash prompt, you’ll need to get the source package and find that file in /home/jcuzella/src/git-core/git-1.8.0/contrib/completion/git-prompt.sh. Install that file somewhere under your home directory and then add a line to your .bashrc file to source it. You’ll know if you need it because you’ll probably see this message after installing latest git:

__git_ps1: command not found
[ ! -e '~/src/git-core' ] && mkdir -p ~/src/git-core && cd ~/src/git-core && apt-get source git-core
[ ! -e '~/src/bin' ] && mkdir ~/bin
cp ~/src/git-core/git-*/contrib/completion/git-prompt.sh ~/bin/
chmod +x ~/bin/git-prompt.sh
echo '. $HOME/bin/git-prompt.sh' >> ~/.bashrc