Skip to content

Instantly share code, notes, and snippets.

@r-a-y
Last active August 28, 2025 17:53
Show Gist options
  • Select an option

  • Save r-a-y/da6c3b1b99aafcb3e97e311280aa9434 to your computer and use it in GitHub Desktop.

Select an option

Save r-a-y/da6c3b1b99aafcb3e97e311280aa9434 to your computer and use it in GitHub Desktop.
Using Git for Windows (PortableGit) with a portable HOME directory

Prologue

I develop on Windows (yeah, I hear your jeers, linux users!), so to use Git, I use Git for Windows

However, I use Git For Windows (portable version) so I can keep my dev environment centrally located. This is so I can reuse this environment simply by copying my msysgit directory to a USB drive.

Installation

(1) Download the latest version of PortableGit:

https://github.com/git-for-windows/git/releases/

You'll want the latest 7z file prefixed with PortableGit in the file name.

Extract the 7z file to a directory of your choosing. For this article, I'll be using c:\PortableGit\ as a reference point.

(2) Setting up your bash environment to use a custom HOME directory

The last step is loading bash and telling it to use a custom HOME directory.

  1. Create a new directory called home\portable\ in the folder that you extracted PortableGit to. eg. c:\PortableGit\home\portable

  2. Next, create a .bat in the main PortableGit folder to launch bash to use our custom HOME directory.

In the following code block, we'll be using Mintty as our terminal to launch bash since it comes with PortableGit.

The most important part in the .bat file is setting our HOME environment variable to use our custom HOME directory.

Copy the accompanying mintty.bat file to c:\PortableGit\mintty.bat.

  1. Launch Mintty by double-clicking on mintty.bat.

The above example uses Mintty, but you could easily modify the .bat file to use some other terminal like ConEmu.

set HOME=%~dsp0home/portable
set "MSYSTEM=MINGW64"
start %~dsp0usr/bin/mintty /bin/bash --login -i
@thierrybo
Copy link

Hi, mintty.bat works. I tried to do the same for git-gui. I created a git-gui.bat with this :

set HOME=%~dsp0home/portable
set "MSYSTEM=MINGW64"
start %~dsp0cmd/git-gui /bin/bash --login -i

and git-gui opens, but it does not work properly:

  • If I create a repository, I get "Failed to create repository ........", but it creates the .git folder :

  • If I try to open this new repository with mintty, it is a valid git repository, but with git-gui, I get "Usage ....\mingw64\libexec\git-core\git-gui [(blame|browser|citool)]"

  • If instead I run "mingw64/libexec/git-core/git-gui" from Mintty, I have no problem creating or opening git repositories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment