Install inside MSYS2 proper - git-for-windows/git Wiki

Please note that this scenario is not officially supported by Git for Windows

Git for Windows being based on MSYS2, it's possible to install the mingw-w64-git package into an existing MSYS2 installation. That means that if you are already using MSYS2 on your computer, you can use Git for Windows without running the full installer or using the portable version. There are some caveats for going this way, details below.

This guide assumes you are comfortable using the command line and you are willing to completely re-install your MSYS2 if something goes wrong. You can contact @Elieux for advice in the git-for-windows/git Gitter room or through the contact channels for MSYS2. Please don't file issues with Git for Windows installed this way until you verify them in an official Git for Windows distribution.

The steps

Here are the steps to install the 64-bit version of Git for Windows to be run in an MSYS2 terminal (msys2_shell.cmd):

  1. Edit /etc/pacman.conf and add the Git for Windows package repositories above any others (i.e. just before [mingw32] on line #71 as of this writing):

    [git-for-windows]
    Server = https://wingit.blob.core.windows.net/x86-64
    
    [git-for-windows-mingw32]
    Server = https://wingit.blob.core.windows.net/i686
    

    (The above is correct. The second, MINGW-only repository is for the other architecture.)

    This step can be done with the following sed command (make sure to do proper backup before trying it):

    sed -i '/^\[mingw32\]/{ s|^|[git-for-windows]\nServer = https://wingit.blob.core.windows.net/x86-64\n\n[git-for-windows-mingw32]\nServer = https://wingit.blob.core.windows.net/i686\n\n|; }' /etc/pacman.conf
    
  2. Authorize the signing key with:

    curl -L https://raw.githubusercontent.com/git-for-windows/build-extra/HEAD/git-for-windows-keyring/git-for-windows.gpg |
    pacman-key --add - &&
    pacman-key --lsign-key E8325679DFFF09668AD8D7B67115A57376871B1C &&
    pacman-key --lsign-key 3B6D86A1BA7701CD0F23AED888138B9E1A9F3986
    
  3. Then synchronize with new repositories with

    pacman -Syyuu
    

    This installs a new msys2-runtime and therefore will ask you to terminate all MSYS2 processes. Save what you need from other open MSYS2 shells and programs, exit them and confirm the Pacman prompt. Double-check Task Manager and kill pacman.exe if it's still running after the window is closed. Start a new MSYS2 terminal.

  4. Then synchronize again to install the rest:

    pacman -Suu
    

    It might happen that some packages are downgraded, this is expected.

  5. And finally install the packages containing Git, its documentation and some extra things:

    pacman -S mingw-w64-x86_64-{git,git-doc-html,git-doc-man} git-extra
    

Now you can close the current shell and open a MINGW64 shell (msys2_shell.cmd -mingw64) to check that everything went well. Run git --version and it should output something like git version 2.31.0.windows.1 (or newer).

If you want to run Git from outside the shells, add C:\msys64\cmd to your PATH, e.g. by using Edit environment variables for your account from the Start menu. It has to come before any other entry pointing inside your MSYS2 installation. If you have installed your MSYS2 into a different directory, correct the path accordingly.

To integrate with the Windows Credential Manager, install the package git-credential-manager.

To be able to view the git man pages when invoking help with git help X or git X --help (in addition to man git-X), add the line export MSYS2_ENV_CONV_EXCL=MANPATH to your shell configuration, and set the man pages as default help format with git config --global help.format man (or append -m to the git help invocation).

Troubleshooting

If you encounter error "error: wrong number of arguments, should be from 1 to 2" with git add -p, set add.interactive.useBuiltin to true in Git's configuration.

Notes

Git for Windows carries an msys2-runtime different from upstream MSYS2, see issue #284 for more details. You can run into some rare issues with programs other than Git due to this. It's possible to keep the stock MSYS2 runtime by moving the msys repository above the git-for-windows repository in /etc/pacman.conf. There are known issues with Git in that case, although not common.

Git for Windows also patches some other packages like cURL and OpenSSL. It unfortunately sometimes causes some packages to be behind in terms of their version, but keeping the upstream packages would most probably lead to a severely broken Git.

The git-extra package modifies the MSYS2 environment heavily (sometimes in ways that are tedious to undo). The package can be skipped if you want to keep your MSYS2 pristine. As of this writing, the package: