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

5

27

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?

Oarsman answered 22/7, 2012 at 19:54 Comment(1)
You can also just point your PATH variable to the git-contrib stuff.Fulford
I
4

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.

Inclement answered 22/7, 2012 at 20:1 Comment(2)
Thanks Adam, makes sense. It's OK, I know how to install git from source, I'm just too lazy to do so. :)Oarsman
it's so simple that lazy is no excuse! :PInclement
C
10

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.

Cornute answered 23/7, 2012 at 13:31 Comment(3)
it works! thanks. this was key: make prefix=/usr/local all ..I'd previously done a vanilla make install of git and the subtree install was failing. One small omission: I was missing an additional dependency asciidoc when doing make install-doc for subtree.Hatband
Also, when not reading your description of the install process, it is unclear from the git docs whether to install and build the subtree contrib project before the git project.Doloroso
I'm confused. If you already have (the latest version of) git installed why do you need to compile from scratch to use something in contribs?Schear
N
8

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.

Nomination answered 27/11, 2012 at 9:31 Comment(1)
Works like a charm (at least on Ubuntu). Much simplier, provided one already has git installed - no need to make and make install entire git from source. Plus - nice to have a man page!Lethia
I
4

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.

Inclement answered 22/7, 2012 at 20:1 Comment(2)
Thanks Adam, makes sense. It's OK, I know how to install git from source, I'm just too lazy to do so. :)Oarsman
it's so simple that lazy is no excuse! :PInclement
J
2

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.

Jurist answered 28/2, 2013 at 23:24 Comment(3)
my answer may be stupid concerning this.. github.com/apenwarr/git-subtree/blob/master/…Jurist
it appears that the latest git where this is available (1.7.11 and up) is not easily available on Debian yet. The latest you get with apt-get is 1.7.10. So this repo might not be so pointless after all.Jurist
It appears to me to be a not so bad idea, provided I didn't find any other solution for standard Windows Git Bash, which comes without make. Installing it with cp git-subtree.sh "$(git --exec-path)"/git-subtree seems to be working fine.Lethia
D
0

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

curl -L https://gist.githubusercontent.com/haf/3426227/raw/a719a28d65478fad8994931b7514d12cce9717c2/install-git.sh | 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.

Doloroso answered 22/8, 2012 at 14:26 Comment(4)
This method caused problems with regards to the git-man, git-core, and gitk packages, and made it impossible to install git-cola without "upgrading" git back to the old version.Nomination
I have had problems with it too. If you have have solutions I'm happy to update the post.Doloroso
First, you need to add apt-get remove git-man to the beginning of the instructions. Then, I suppose using checkinstall to provide fake git-man, git-core and gitk packages would improve matters. You probably need to specify a high enough version number to checkinstall that would prevent apt from "upgrading" the package. I gave up before trying all that and ended up doing what my answer describes.Nomination
For anyone who comes across this in this day and age, the URL to curl is https://gist.githubusercontent.com/haf/3426227/raw/a719a28d65478fad8994931b7514d12cce9717c2/install-git.shGorge

© 2022 - 2024 — McMap. All rights reserved.