8

I'm looking to install Git in a custom location different from the default usr/local/git/bin/git directory that the package installer from the http://git-scm.com/ website installs to.

For example, I just tried copying the contents of usr/local/git to /Users/braitsch/my-git and updating my path variable to /Users/braitsch/my-git/bin and now Git's unhappy saying that it can't find some of its commands such as git -stash.

I also just tried setting ./git exec-path=/Users/braitsch/my-git/libexec/git-core but that doesn't seem to be taking.

So my question is how can I setup a custom install of Git without the use of package managers or pre-built installers? I'd love to find a scenario that I could easily use on both Mac and Windows.

Update

It looks like Git stash (and possibly other commands) will fail if you move the directory that gets installed at usr/local/git via the package installer to another location. How can I get around this? I'm trying to run Git from a custom location but it appears this is not possible via the builds on the http://git-scm.com site?

halfer
  • 19,824
  • 17
  • 99
  • 186
braitsch
  • 14,906
  • 5
  • 42
  • 37
  • You did update your path to `/Users/braitsch/my-git/bin`, right? Not `/Users/braitsch/my-git/bin/git`? – VonC Oct 04 '11 at 15:53
  • I did, sorry that was a typo. Just made the fix. Everything appears to be working with this setup except git stash.. Do you happen to know, is everything Git needs contained in that `usr/local/git` directory that the package installer creates or does Git reach out to other dependencies on the file system? Thanks again. – braitsch Oct 04 '11 at 16:13
  • What exact command are you typing for `git stash`? (and what the exact error message?) (because you did write `git -stash` with a '-') – VonC Oct 04 '11 at 17:10
  • If I cd into a git repository and run `git stash list` I am getting `git: 'stash' is not a git command. See 'git --help'.` What's strange is that stash works fine when I run it against an instance of git installed via the package on the git-scm site, but if I move the directory at usr/local/git anywhere outside of usr/local the command fails. Every other command I've tested appears to be working fine. Does `stash` rely on dependencies outside the core git package? Thanks again. – braitsch Oct 10 '11 at 16:50
  • For the record I've also tried `git --git-dir=./git --work-tree=. stash list` but to no avail. – braitsch Oct 10 '11 at 16:54
  • You are using a recent git, right? at least a 1.5.3? http://lists.gnu.org/archive/html/qemu-devel/2009-04/msg01797.html – VonC Oct 10 '11 at 16:56
  • Yup, I was originally experiencing the issue with 1.7.5.4, just tried with 1.7.7 and the issue persists. – braitsch Oct 10 '11 at 17:08
  • Is there any alias in place? Either for `git` itself, or for git aliases (`git config alias`)? – VonC Oct 10 '11 at 18:00
  • `git config alias` outputs `error: key does not contain a section: alias` and I don't have any alias' in my .profile that reference git. – braitsch Oct 10 '11 at 18:15
  • It's really strange. I moved `usr/local/git` to `Users/braitsch/git` updated my PATH and everything works fine except for `git stash`. If I reinstall git via the package installer (re-create the /usr/local/git dir) my PATH still calls commands against the instance in my home directory but `git stash` will work again. – braitsch Oct 10 '11 at 18:24
  • There must be a script with an hard path in it. – VonC Oct 10 '11 at 18:26
  • That's my assumption as well :/ – braitsch Oct 10 '11 at 18:28

3 Answers3

5

What works fine for me (including git stash) is to clone the git repository, e.g. with:

cd
git clone git://github.com/gitster/git.git
cd git
make

(I had previously installed the build dependencies with sudo apt-get build-dep git, which will work on a recent Debian-based distribution - otherwise if you get a build error you'll just have to install git's build dependencies with whatever mechanism you normally use.)

Then you can call this git with:

$ export GIT_EXEC_PATH=~/git/
$ ~/git/git --version
git version 1.7.7.rc0.72.g4b5ea

... or using ~/git/git --exec-path=/home/mark/git instead of the environment variable.

You can move the built source tree to anywhere, and it still works, e.g.:

$ mv ~/git ~/tmp/
$ export GIT_EXEC_PATH=~/tmp/git/
$ ~/tmp/git/git --version
git version 1.7.7.rc0.72.g4b5ea
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • Hi Mark, thanks for your response but unfortunately this isn't working for me. Attempts to set `--exec-path` to anything throws an error e.g. `git --exec-path=/Users/braitsch/test-dir/git` and setting the ENV variable via export GIT_EXEC_PATH appears to be ignored. It seems I can only get stash and now clone (over https) to work if and only if I leave Git in the same location where I compiled it. Am I missing something from your instructions above? Thanks again for your help. – braitsch Oct 29 '11 at 17:30
  • Just to expand on this, after moving the directory of compiled code requests to `git clone` and `git fetch` fail over https with `fatal: Unable to find remote helper for 'https'` I believe because moving the directory breaks the path to libcurl. – braitsch Oct 29 '11 at 17:44
  • Thanks Mark, I did finally get this working after multiple attempts. I'm still unable to set the GIT_EXEC_PATH however the compiled code does appear to be portable between machines and around my file system which is exactly what I am after. Thanks again. – braitsch Nov 22 '11 at 07:42
  • 1
    Setting `export GIT_EXEC_PATH=/my/path/usr/libexec/git-core` (and putting that into the active profile) worked for me. I was about give up on the idea that I could install git without a package installer but this solved the final hurdle. This is a useful thing for npm too, since that uses git. – Kevin Teljeur Mar 05 '19 at 11:28
2

I would just re-build it from source. Grab a tarball from http://git-scm.com/ then build it using ./configure --prefix=/path/to/my-git/.

Edit: I'm not sure off the top of my head how to make a relocatable git installation, but if you start by building it with a particular, unique, prefix, installing it, then grepping through the installed files for the prefix (ie, grep -R my-git /path/to/my-git/), that would likely be a good starting point.

David Wolever
  • 148,955
  • 89
  • 346
  • 502
  • I vote for this. If you're bypassing your package manager, best bypass it completely and do everything yourself. – Noufal Ibrahim Oct 10 '11 at 17:42
  • Thanks guys. What I'm really trying to do is find or produce a self contained binary or package that I can also port to other machines. I'm in the process of building a Git client and am trying to avoid the scenario of forcing users to manually install Git or other dependencies to get Git running on their machine. If I compile from source won't that tie the instance I create to my specific machine? – braitsch Oct 10 '11 at 18:20
-2

Use a VM (virtualbox is free) and build and use on a Linux machine. Having built your own, you can switch versions quite easily.

Hope this helps.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141