DaveG DaveG - 1 year ago 54
Git Question

How can I minimise what is installed by Git for Windows?

The git for Windows client appears to install an entire mingw distribution onto my machine consuming over 500MB of space.

This is nearly twice as large as the installation of Gimp for Windows!

I already have cygwin, vim and all of the other utilities I need to do my job and so have no need whatsoever for yet another copy of perl, vim, etc. I just need a git client for Windows.

How can I minimise what is being installed so that I just get a git client I can use?

Answer Source

Two things are in play here:

  • Whatever tool you have used to calculate the space occupied by the GfW install did it wrong; here's why.

    Due to historical reasons many "supplementary" Git executable files are now just "alternative names" for the main executable file, git.exe.

    To achieve this, the installer writes the git.exe file and then creates a bunch of the so-called "hard links" all pointing to that git.exe executable. This means a bunch of files named git-*.exe located in the mingw32\libexec\git-core are all mere hardlinks.

    In my (somewhat dusty) GfW install, there are 116 hardlinks to git.exe there. Multiply that by circa 3 MiB and you get a value close to 350 MiB.1

  • Most (trust me) of the bundled stuff you thnk is not related to GfW is in fact crucial for it to work, because:

    • Some bits of Git core functionality are written as shell scripts. A good example is git-rebase which has been re-written in C only 2 minor Git releases ago.

      Shell script implies the need to have a Windows port of a POSIX shell; so GfW bundles bash. It also implies the need to have a set of utilities any Unix shell programmer expects to have available—such as sed or awk etc (not "just because" but because they are indeed used by some parts of Git code).

    • The git svn bridge is written in Perl and requires several Perl modules to be available as well as a client Subversion library.

      While not a core component, many folks take its existence for granted, so it's here.

    • The stock GUI utilities, git gui and gitk are written in Tcl/Tk,…so guess what.

      And again many folks take their availability for granted (me included).

    • The OpenSSH SSH client is bundled for the same reason.

    • The support for HTTP[S] protocol in Git is implemented using libcURL which depends on a bunch of stuff including OpenSSL.

    • Now consider that many parts of those pieces of software I enumerated have their own hard dependencies which need to be bundled as well.

So, we are basically left with two bundled pieces of software which are not strictly needed: Vim and Mintty. The opinion of the folks working on GfW is that they are expected to be available by those who prefer to work with GfW from the Git Bash window. Simply put, they are there for those who came from Unix land or switch systems back and forth between Windows and Unix-like ones (Mac OS X included).

So… If you think about this a bit more, when, say, on a typical GNU/Linux-based OS you do somehing like

apt install git git-gui gitk git-svn

you just don't give a heck about the dependencies because

  • Everything just works and
  • Chances are very high you already have 95% of the dependencies (including the transitive ones) installed anyway.

This makes the installation of Git to appear as if it has almost zero dependencies which is wrong.

Windows, on the other hand,

  • Does not have a package manager. (And no, Chocolatey and NuGet are not them.)
  • Does not have those 95% of of "the dependencies" already installed.

As you can supposedly see now, the GfW developers had no other sensible way to go around implementing this product short of bundling all that stuff. After all, a typical Joe Random Developer expects to download the installer, click through it and get a fully working product as the result.

The situation is going to improve on this front a bit: since the start of the 2.x branch, GfW strives to piggyback on the Msys2 ecosystem as much as possible, and this includes its package management facility (based on the Windows port of pacman IIRC). I'm not sure whether it works now but the goal was to eventually make GfW installable piecemeal by having it available as a set of Msys2 packages. If you want a status update on this, feel free to ask on the GfW mailing list.

To recap, if not already there, there will be two ways to get GfW on your system: via the (full) installer and via the Msys2 ecosystem and its own package manager. The latter facility will enable you to install only a minimum amount of stuff (in exchange to some overhead incurred by the package manager's bookkeeping).

1 That won't work if you have installed GfW on a filesystem which does not support hardlinks—such as FAT32.