24

I have a rough idea that git.cmd is only a wrapper (but added to PATH by default), but I found out that git.exe works as well and I intend to use it as a workaround to this issue (comments to it rather, regarding chcp on XP64). Would that be not recommended for any reason at all? Also, is git.cmd really needed in the first place?

Note: The chcp issue I am referring to is not caused by missing PATH entries as in 'chcp' is not recognized as an internal or external command, operable program or batch file. on a Windows PC

1
  • There is no such thing as git.cmd. At least not in the version i am using which is 2.19.0. There is a git-cmd.exe and a git.exe in the folder cmd\git.exe
    – joedotnot
    Commented Dec 8, 2018 at 2:14

3 Answers 3

34

git.cmd no longer exists in current versions of msysgit (e.g. 1.8.0). git.cmd was a wrapper that has been replaced by a new wrapped called git.exe. This is not to be confused with the actual git.exe.

If you take a look at the Git directory in %ProgramFiles(x86)% or %ProgramFiles%, you will see the following structure:

Git
|-- bin
|   |-- git.exe
|-- cmd
    |-- git.exe

The wrapper has existed in msysgit for a long time in order to properly set up the environment for using git from cmd.exe. If you are using the included bash shell, it will run git.exe directly.

You can compare the old cmd version with the new executable wrapper here:

  1. git.cmd
  2. git.exe wrapper

You don't really need to worry about any of this magic, just understand that you should call the wrapper from anything but the msysgit bash environment. When you add git to the path in the installer, it's the Git\cmd directory that is added. I don't recommend ever adding all the included utilities to your system path, as this can cause a lot of problems, especially if you have other msys or cygwin installations. I've never actually tried it in recent memory, but I would imagine it puts both the cmd and bin directories in your path, with cmd taking precedence.

For me, there is one huge advantage to the new git.exe wrapper: it makes code that calls git more portable. Previously, if I wrote a python script that called git, I would have to either execute the command with a shell environment (subprocess.Popen() with shell=True) or run the cmd file explicitly. Now, I can just execute a process with 'git' as the name, regardless of the OS. This is because CreateProcess() on Windows will not execute a batch file (.cmd is an alias for .bat), you need to invoke cmd.exe to execute it.

13

There are three options when you install msysgit.

  1. The first is that nothing is put on PATH and you have to use Git Bash.

  2. The second is that git.cmd and gitk.cmd are added to PATH so that you can use it in cmd, Powershell, cygwin etc. without affecting other tools that you have on Windows. ( This git.cmd is a wrapper enabled you to do this, to answer the question).

  3. The third ( my favourite) is to add all the tools, and git.exe, in PATH and use this. This will affect Windows tools and you will be able to use the full set of tools that MSYS comes with.

I have always used the third option. I have never seen how it affects me ( I use Powershell and powershell cmdlets and never standard Windows commands) If you are like that and you want Mingw exes at your disposal, go for the third option and you will be good.

5

According to the git for windows installer you have the option of adding git.exe to your path during the setup. You should be fine using that option.

Option screen to select git.exe

2
  • so is it correct to say that the use of git.cmd alludes to the first option?
    – prusswan
    Commented Jan 20, 2012 at 20:16
  • AFAIK yes, I would chose the second option if you want to use git.exe from the regular cmd prompt.
    – Devin M
    Commented Jan 20, 2012 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.