How do I correctly install the tools in git's contrib directory?

Git includes a set of tools contributed by third parties. I'm not sure how I'm supposed to use these tools correctly.

For example, I'd like to use git-subtree. There seem to be a number of ways I could use this:

  1. Copy to my path

    cp /path/to/git-subtree.sh /usr/local/bin/git-subtree
    chmod +x /usr/local/bin/git-subtree
    

    Works fine, feels a bit hacky.

  2. Symlink to my path

    chmod +x /path/to/git-subtree.sh
    ln -s /path/to/git-subtree.sh /usr/local/bin/git-subtree
    

    Also works, feels marginally less hacky

  3. Use a git alias

    Add the following to my global .gitconfig file:

    [alias]
        subtree = !/path/to/git-subtree.sh
    

    Then good old chmod again:

    chmod +x /path/to/git-subtree.sh
    

    Works, feels all nice and git-ish.

  4. Use the Makefile

    Per the INSTALL file.

    cd /path/to/git-subtree.sh
    make
    make install
    make install-doc
    

    Doesn't work for me, it tries to install to a non-existent path. Perhaps this is because I installed git using homebrew rather than installing from source? I'm too lazy to investigate; I already have three working alternatives. :)

So my question is, which of these is the preferred way of installing git-contrib add-ons? Is there even a preferred way? Is there another option I haven't suggested that's better than the ones listed above?

Answers


Contribs is a collection of helpful things. You don't install them as a package. For example, to install the tab completion, you simply source that script from your .bash_profile script. Each contrib in that folder has it's own way of using it.

as for compiling git from source

make
sudo make install

after you install all the prerequisites.


from git/contrib/git-subtree:

HOW TO INSTALL git-subtree ==========================

First, build from the top source directory.

Then, in contrib/subtree, run:

 make
 make install
 make install-doc

If you used configure to do the main build the git-subtree build will pick up those settings. If not, you will likely have to provide a value for prefix:

 make prefix=<some dir>
 make prefix=<some dir> install
 make prefix=<some dir> install-doc

To run tests first copy git-subtree to the main build area so the newly-built git can find it:

 cp git-subtree ../..

Then:

 make test

I just verified that this works:

  1. downloaded source via existing git
  2. installed build deps

    $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
    
  3. check out the latest release branch and build

    $ git co v1.7.11.3  
    $ make prefix=/usr/local all  
    $ sudo make prefix=/usr/local install  
    
  4. build and install contrib/subtree

    $ cd contrib/subtree  
    $ make  
    $ make install  
    $ make install-doc   
    
  5. verify it all works

    /usr/local/bin/git  
    [todd@montreal-01 subtree ((v1.7.11.3))]$ git --version  
    git version 1.7.11.3  
    

Check, we have the latest git.

[todd@montreal-01 subtree ((v1.7.11.3))]$ git subtree  
usage: git subtree add   --prefix=<prefix> <commit>  
    or: git subtree merge --prefix=<prefix> <commit>  
    or: git subtree pull  --prefix=<prefix> <repository> <refspec...>  
    or: git subtree push  --prefix=<prefix> <repository> <refspec...>  
    or: git subtree split --prefix=<prefix> <commit...>

    -h, --help            show the help  
    -q                    quiet  
    -d                    show debug messages  
    -P, --prefix ...      the name of the subdir to split out  
    -m, --message ...     use the given message as the commit message for the merge commit  

options for 'split'  
    --annotate ...        add a prefix to commit message of new commits  
    -b, --branch ...      create a new branch from the split subtree  
    --ignore-joins        ignore prior --rejoin commits  
    --onto ...            try connecting new tree to an existing one  
    --rejoin              merge the new branch back into HEAD  

options for 'add', 'merge', 'pull' and 'push'  
    --squash              merge subtree changes as a single commit  

Check, we have subtree working.


Here's the simplest thing that worked for me, installing git-subtree on Ubuntu 12.10:

Get the code

git clone https://github.com/git/git.git --depth=1
cd git/contrib/subtree
make

"Install" it into the git tools directory

sudo cp git-subtree /usr/lib/git-core/

For the man page, you need asciidoc which is not a small installation, but if you have it:

make doc
gzip git-subtree.1
sudo cp git-subtree.1.gz /usr/share/man/man1

And that's it.


All of this looks a bit more complex than necessary .. (maybe because the install.sh is a recent addition?) This is what worked for me. Or so it seems.

# go to a directory where it's ok to put temporary stuff
cd ~
git clone git://github.com/apenwarr/git-subtree.git
cd git-subtree/
# shell script does the job for you.
sudo sh ./install.sh
cd ..
# remove the git cloned stuff, now that all relevant things have been copied (we hope)
rm -r git-subtree

# test that it works
git subtree
# should print some help/usage stuff.

There is an instruction saying mostly just that: https://github.com/apenwarr/git-subtree/blob/master/INSTALL

I am a bit more stupid than that. I need to be told that I have to download (git clone) the thing to an arbitrary location before I run the shell script, and that this stuff can be disposed afterwards.

The contents of the install.sh are quite revealing, https://github.com/apenwarr/git-subtree/blob/master/install.sh If you ever want to install a git thingie that doesn't provide an install.sh of its own, this could be a place to start.


All of the below in one command, tested in Ubuntu only:

curl -L https://raw.github.com/gist/3426227 | bash

Now, here's how to install latest git with git as a package in ubuntu

To do it as a package (preferrable):

sudo apt-get remove git -y
sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc

If you don't install asciidoc, ignore the line with make target 'install-doc', below.

This will checkout the master/latest tagged release and install it with checkinstall as a package.

git clone https://github.com/git/git.git
cd git
make prefix=/usr/local all
sudo checkinstall --pkgname=git make prefix=/usr/local install

then the contrib:

cd contrib/subtree
make prefix=/usr/local
sudo checkinstall --pkgname=git-subtree make prefix=/usr/local install

...answer yes or y to the question whether to exclude the files from the home folder.

sudo checkinstall --pkgname=git-subtree-doc make prefix=/usr/local install-doc

...answer yes or y to the question whether to exclude the files from the home folder.

You can now handle the git package:

dpkg -r git

and the subtree package:

dpkg -r git-subtree
dpkg -r git-subtree-doc

If you don't feel like having half a gigabyte of latex perl scripts hogging harddrive space afterwards:

sudo apt-get remove asciidoc -y
sudo apt-get autoremove -y

Or all of it (all build deps)

sudo apt-get remove -y libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc
sudo apt-get autoremove -y

Thanks to @toddg for the basic commands that I needed!

I haven't been able to make git subtree --help look up the correct man page yet.


Need Your Help

Cannot assign to struct field in a map

go

I have the data structure like this:

How to make Android GridLayout compatible to older version?

android android-layout user-interface grid-layout

New GridLayout for Android 4 is good. Both in terms of code maintainability and performance.