Skip to content

Instantly share code, notes, and snippets.

@piotrkundu
Last active April 3, 2024 06:36
Show Gist options
  • Save piotrkundu/e7d94204dd3c48525b23c59fe5d23478 to your computer and use it in GitHub Desktop.
Save piotrkundu/e7d94204dd3c48525b23c59fe5d23478 to your computer and use it in GitHub Desktop.
Full MINGW64 environtment with MSYS2 instead of Git Bash for Windows

BACKGROUND (WHY?)

I switch dev-environments every single year with each customer having their own setup. Git on Linux and MacOSX just works most of the time - there are some SSH keys needed to be setup, but "sudo apt-get" or "brew install" mostly does the trick.

Git for Windows is a box a sourcery, so when you install that you will get a version of slim MSYS2, MinGW64 and most importantly bash and git that runs from the bash. This is what you need 9 out of 10 times, if you ONLY need to use git to manage your source and then use other/external toolchains like VS Code, VS2022 or Windows Powershell or Command to compile your sh.ttt I mean stuff.

Then that 10th out of 10 times, you want to compile windows applications from the same terminal that you run git - just like you do on linux or OSX. If you are running Windows alone then having two terminals, one for git (with mingw64/msys2) and one for your ms whatever the compiler name is for C++.

But if you work on multiple platforms then it's just a hustle to keep up with which remote window goes to which OS, or if you are running on OSX and have two instances of Pararells, onw for Windows and one for Linux. Some people can have 64 tabs in the browser and know exactly what is what - not me. So I want a work process that differs as little as possible from OS to OS. Unfortunately you cannot do that with Git for Bash, because you do not have all the dependencies you need - I don't remember if the limitations was pacman or something else.

LINKS: https://gist.github.com/adojos/0abab00dd7e6bd84db39a760fb40a340

WHEN?

Now when I have a new Windows 11 machine installed from scratch I decided to do it the right way, so install MinGW64 and MSYS2 and the git on top of that so I'm no limited in the future.

HOW?

It took me a couple of times, before I got it right and pay attention to details:

  1. Download and install MSYS2 (https://www.msys2.org/). Follow steps 1-4 (of 9).
  2. When running MSYS2 (Step 5)
pacman -Syu
  1. Restart MSYS2 from Start Menu (Step 6 and 7). This updates MSYS and installs MinGW64 toolchain
pacman -Syu
pacman -S --needed base-devel mingw-w64-x86_64-toolchain

  1. Add "Git for Windows" pacman entry:
nano /etc/pacman.conf

and then add this two sections

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

[git-for-windows-mingw32]
Server = https://wingit.blob.core.windows.net/i686
  1. Setup/install/download the PGP keys. I was on a corporate VPN and got this SSL_ERROR_SYSCALL error so I had to disconnect from VPN.
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
  1. And update (yes it's the third time)
pacman -Syyuu
  1. Restart MSYS2. Close MSYS2 and start again from Start Menu (yes, the fourth time)
pacman -Suu

  1. Install the MinGW64 version of git that runs nativly (faster?)
pacman -S mingw-w64-x86_64-{git,git-doc-html,git-doc-man} git-extra

  1. Running git in the current MSYS2 terminal window then nothing will happens, except some well chosen words of frustration.

  2. Close that window and open the MinGW64 version of msys. You can just use the search function from Start and search for "msys mingw x64".

differetn_version


This is how it looks like when you get it right

result


DO NOT DO: pacman -whatever git <-- it's the msys version with POSIX emulation and not the mingw version that uses native calls. Not sure it matters on my i9-12900K, but it just feels better to save a few clock cycles.

LINKS: https://github.com/git-for-windows/git/wiki/Install-inside-MSYS2-proper


TROUBLESHOOTING

If you get this error when starting MSYS -bash: create-shortcut.exe: command not found - maybe you are on Windows 11 ?

create_shortcut

  1. Open C:\msys64\etc\profile.d\git-sdk.sh with Sublime Text(https://www.sublimetext.com/download)
  2. Comment out the sdk create-desktop-icon --gentle commetn
@piotrkundu
Copy link
Author

Now you need to setup your git aliases, ssh keys and password management (ssh-agent).

@piotrkundu
Copy link
Author

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