Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git.cmd vs git.exe - what is the difference and which one should be used?

Tags:

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

like image 440
prusswan Avatar asked Jan 20 '12 19:01

prusswan


People also ask

Should I use Git Bash or Git CMD?

It is up to you to decide which you want to use. As many others, I recommend you to learn Git with command line before switching to a graphical interface. If you don't know which to choose between Git Bash and Git CMD, I'd go for Git Bash since bash is a really useful tool to learn.

What is Git CMD used for?

At its core, Git is a set of command line utility programs that are designed to execute on a Unix style command-line environment. Modern operating systems like Linux and macOS both include built-in Unix command line terminals. This makes Linux and macOS complementary operating systems when working with Git.

Can I use Git with command prompt?

Using Git. Now it's installed, Git will work the same way as it does on Linux or OS X. All you have to do is load Command Prompt (Load the Start menu, then click "Run", type cmd and hit enter), then you can use Git commands as normal.

Where is Git CMD EXE?

The default path on windows is C:\Program Files (x86)\Git . The name of the executable is not git.exe on all systems.


2 Answers

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.

like image 77
djs Avatar answered Oct 05 '22 23:10

djs


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.

like image 27
manojlds Avatar answered Oct 06 '22 01:10

manojlds