🔗Introduction

Vagrant is a modern way to define the requirements of a project. In the case of Git for Windows, it allows us to set up a minimal virtual Linux machine that makes it easy to run the same revision of Git on Windows as well as on Linux without much effort.

Note: while Vagrant makes things easy, quite a bit of bandwidth is required for the setup (roughly a gigabyte will be downloaded in total).

🔗How to install

  1. Download and install VirtualBox
  2. Download and install Vagrant
  3. Install the Git SDK
  4. Run vagrant up in the /usr/src/git directory
  5. Run vagrant ssh

Note that the prompt shows that the current directory in the ssh session inside the virtual machine is /vagrant/ and that the files in that directory are suspiciously identical to the /usr/src/git/ directory in your Git SDK installation. This is not by accident. In fact, the /vagrant/ directory inside the virtual machine is the /usr/src/git directory of the hosting Git SDK. Note: This implies that the file names are case-insensitive, still, even if running inside a Linux VM.

To compile and install Git, you will have to run make clean first because Git will have built Windows binaries in the same directory (when we will need Linux binaries inside the virtual machine started by Vagrant). After calling make install and export PATH=$HOME/bin:$PATH you will be able to run the Git version built from the source files in /vagrant/git/.

🔗Alternative to the Git SDK way

If you cannot download and install the Git SDK for some reason or other, you could also clone the Git source code using Git for Windows instead, but make sure that Unix line endings are used: git clone -c core.autocrlf=false https://github.com/git-for-windows/git vagrant-git. If Git for Windows does not even work for you, you could also download the source code as a .zip and unpack it.

After that, continue with the vagrant up step above.

🔗Why?

Git was born on Linux. Over the years, it has become more and more platform-independent, but still support for Linux outshines support for every other platform, including Windows. Therefore it is preferable under certain circumstances to run Git inside Linux in a virtual machine, for example

🔗Known problems

🔗Tips & Tricks

🔗Use tmpfs

Linux offers a plethora of file systems optimized for different use cases. One of them is tmpfs, a RAM-based file system which keeps all files in virtual memory and is therefore very fast (but does not persist any of the data to disk).

Using such a file system can speed up Git operations quite substantially, in particular when performing disk-intensive operations, such as git filter-branch, git gc or git svn. It is very easy to create a tmpfs-backed file system:

mkdir -p $HOME/tmp
sudo mount -t tmpfs -o size=10G tmpfs $HOME/tmp
cd $HOME/tmp

You will want to clone projects into that $HOME/tmp/ directory so that the I/O intensive operations benefit fully from using Vagrant.