Search code examples
gitpowershellwindows-subsystem-for-linuxposh-git

Git recommendations, cygwin, WSL, PowerShell posh-git Module


I'm quite new to using git, so I'm not very knowledgeable, but have some questions, specifically about using git on Windows.

  • Do I have to use git from https://git-scm.com/downloads or can I use other implementations of git?
  • Alternatively, there is the posh-git PowerShell Module. Can the Cmdlets / Functions in here do everything that git do and so make downloading and installing git?
  • For now, I'm installing via chocolatey cinst -y git installs also the cygwin. I have a problem with cygwin in that it's somewhat redundant these days, especially with things like WSL. Is it possible to just install the git commands without cygwin (I guess I just need the git.exe right?). I used to love cygwin and use it all the time, but in 2020, it does seem somewhat redundant, right?
  • Alternatively, should I just install WSL and then go in there and sudo apt install git and then go back into Windows and just create a PowerShell function (using the wsl method to gain access to a command in the default WSL installation from Windows)? I think something like this should work:
    function git { wsl git }
    

Advice from experts on which of the above would be most efficient and sensible would be appreciated.


Solution

  • If you want a native Windows version of Git, the recommended option is Git for Windows, which you can download from that link or with Chocolatey. Because Git is designed for Unix, you do need a POSIX shell and a POSIX environment, which is shipped with Git for Windows. This is based off of MINGW, not Cygwin, but it is required so that programs written in shell, as well as things that invoke the shell like your editor, work. posh-git doesn't change that.

    You can indeed use Git from WSL, but I would not recommend using it from a non-sh environment such as PowerShell. That's because a Unix Git will expect paths and such to be in the Unix format and won't accept any sort of Windows paths at all. So you can use WSL Git, but I strongly recommend using it from WSL and not PowerShell.