Issue

Many development tools rely on the fact that git.exe is installed to perform source control operations e.g. VSCode. However, a common problem I have seen is that security settings on many corporate Windows devices do not allow the installation of git CLI using an MSI file by the user. VSCode is an approved application, or installed as a user application as opposed to a system one, so is available but limited by it’s lack of source control features.

In some cases, you can get around this problem if you have a means to install a ‘corporate approved application’ from a location such as the Microsoft Store that includes git.exe as part of it’s bundle. A good candidate is the GitHub Desktop

Process

Find the git.exe

In this scenario GitHub Desktop will probably be installed as a user application, not a system application i.e. the files are in the c:\users folder structure.

To find the actual location do the following

  1. Open Windows Explorer
  2. In the address bar type %appdata% this is the shortcut code to the current users local storage
  3. Windows Explorer will open the folder C:\Users\<yourname>\AppData\Roaming
  4. There is a GitHub Desktop subfolder in this folder, but it is just the local cache. For the executables you need to change folder to C:\Users\<yourname>\AppData\Local\GitHubDesktop
  5. Change into the newest version folder and keep going down to the git.exe version folder C:\Users\<yourname>\AppData\Local\GitHubDesktop\app-3.3.8\resources\app\git\mingw64\bin (you may have more than one version installed, so pick the newest)

Adding Git Support to VSCode

VSCode finds it’s copy of the git.exe (to provide source control) using a value in its settings file. To update this value

  1. Open VSCode
  2. Open the settings (menu File → Preferences → Settings)
  3. Use the search option to search for git.path
  4. Edit the settings file to add a path to the git.exe

Note: This path must use double \ and ends with the name of the executable git.exe

    {
    
    "git.enabled": true,
    "git.path": " C:\\Users\\<yourname>\\AppData\\Local\\GitHubDesktop\\app-3.3.8\\resources\\app\\git\\mingw64\\bin\\git.exe"

         Other settings
    }
  1. Save the changes to the settings file and restart VSCode
  2. If you open VSCode on a folder that is a git repo the Source Control options should be enabled

Adding Git support to the command line

In many cases being able to run git commands at the command line, in a command prompt, PowerShell window or VSCode terminal is advantageous.

All command prompt types in Windows find executables by the use of a PATH value. To set a user defined path to the git.exe do the following

  1. Press the Windows key to start a search and type settings to load the settings panel

  2. In the search box type environment and pick Edit environment variables for your account

  3. Select the Path entry in the user variables, an editor will open

  4. In the editor add a new row with the value

    C:\Users\<yourname>\AppData\Local\GitHubDesktop\app-3.3.8\resources\app\git\mingw64\bin

    Note: This is a path to the folder, not the git.exe and needs only single \

  5. Save the changes

  6. Close and reopen any command prompts. You should now be able to issue git commands

POSH Git

PowerShell Git (POSHGit) is a tool I find very useful that provides information on the state of a git repo within the command prompt.

Usually it is installed to a system adding using a tool such as Chocolatey or PowerShellGet. Details of how to run these commands (as a non administrator) are detailed in the project homepage.

However, again corporate security may block these options. Luckily as POSHGit is just a PowerShell module there are also instructions for a manual install i.e

  1. Download the current POSHGit PowerShell module from its GitHub Release page and place in a folder on your device

  2. Open a PowerShell prompt

  3. Edit the PowerShell settings, to do this at the prompt type notepad $profile

  4. Add the following line with the correct path to where you saved the post-git.psd1 file

    Import-Module 'C:\tools\posh-git\src\posh-git.psd1'

  5. Save the file and restart the PowerShell prompt (this will load the module)

  6. If you change directory to a git repo folder and you should see the prompt change based on the state of the git repo

Summary

So, by using the git.exe from a corporate approved application such as GitHub Desktop, and setting the PATH and VSCode settings to point to this version, you can get around the problem of not being able to install git.exe on your corporate device using an MSI.

Thus getting the advantages of the CLI whilst remaining within the corporate security guidelines.