79

I have installed msysGit 1.7.10 on my Windows 7 machine. What I need to know is if I can still use Git from command line?

When I try the git command in the command line right now I see:

'git' is not recognized as an internal or external command, operable program or batch file.

Is there any way I can enable the Git command line?

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
Ayusman
  • 8,509
  • 21
  • 79
  • 132
  • 4
    Set your `PATH` environment variable to point to where msysgit's bin is. – wkl Jun 12 '12 at 16:36
  • 1
    @birryree thanks. I re-installed with Git Bash option and it seemed to work fine. – Ayusman Jun 12 '12 at 17:22
  • 1
    This answer fills in the details -> http://stackoverflow.com/questions/3426347/how-to-run-ruby-and-git-commands-in-one-place-on-windows – csi Oct 03 '12 at 23:40

9 Answers9

87

I had the same issue and resolved it by adding the /bin directory location to the PATH Environment Variable.

  1. Search for the file location where Git was installed, mine is C:\Users\(My UserName)\AppData\Local\GitHub. It may also be C:\Program Files (x86)\Git

  2. Once you have the location of Git you should see a /bin sub-folder. It may be in a PortableGit folder (mine is PortableGit_015aa71ef18c047ce8509ffb2f9e4bb0e3e73f13). Copy this path.

  3. Go to Control Panel > System > System Protection > Advanced > Environment Variables

  4. Choose PATH, click edit and paste the bin path there. If there are already any values in your PATH paste your Git path at the end separated with a semi-colon.

Now you can access Git command from CMD.

ajcw
  • 23,604
  • 6
  • 30
  • 47
  • 2
    By doing this, you also put other Unix commands on your path (e.g., there may be a conflict between Windows `find` and Unix `find`). This *is* a good answer, and it works for me. Just be forewarned. – golfer9338 Dec 29 '14 at 12:15
  • 1
    This solves the problem, but the PortableGit_ directory will change names, because of the hash code, so I have to modify the PATH environment, how to solve this problem? – Justin Civi Feb 25 '15 at 14:03
  • mine happened to be C:\Program Files\Git\bin – brianyang May 13 '20 at 17:32
39

As @birryree said, add msysgit's binary to your PATH, or use Git Bash (installed with msysgit as far as I remember) which is better than Windows' console and similar to the Unix one.

Samy Dindane
  • 17,900
  • 3
  • 40
  • 50
  • 11
    Note that Git bash does not support non-ASCII characters. This might not be an issue, but the OP should be warned anyway. – kostix Jun 12 '12 at 18:23
23

These instructions worked for a Windows 8 with a msysgit/TortoiseGit installation, but should be applicable for other types of git installations on Windows.

  • Go to Control Panel\System and Security\System
  • Click on Advanced System Settings on the left which opens System Properties.
  • Click on the Advanced Tab
  • Click on the Environment Variables button at the bottom of the dialog box.
  • Edit the System Variable called PATH.
  • Append these two paths to the list of existing paths already present in the system variable. The tricky part was two paths were required. These paths may vary for your PC. ;C:\msysgit\bin\;C:\msysgit\mingw\bin\
  • Close the CMD prompt window if it is open already. CMD needs to restart to get the updated Path variable.
  • Try typing git in the command line, you should see a list of the git commands scroll down the screen.
James Lawruk
  • 30,112
  • 19
  • 130
  • 137
14

In windows 8.1, setting the PATH Environment Variable to Git's bin directory didn't work for me. Instead, I had to use the cmd directory C:\Program Files (x86)\Git\cmd.

Credit to @VonC in this question

Community
  • 1
  • 1
Error
  • 820
  • 1
  • 11
  • 34
2

For me, I'm using Windows 10, @andrew-marshall's instructions worked (Thanks!) except that git.exe was within a cmd directory within PortableGit..., not bin, so I had to put \cmd on the end of the path I added to PATH. Thought I would post this here in case anyone else hits the same issue. You can tell it works once git in a new Command Prompt window returns command usage info and not an error.

Alex Bowyer
  • 681
  • 1
  • 6
  • 17
1

In the latest version (v2.19 for Windows when I'm writing), if you choose the option "Use git in Windows command prompt" (or sth similar, please read the options carefully when you install git), you should be able to use git commands in windows command prompt or windows powershell without any additional setting. Just remember to restart the command line tool after you install git.

zinc
  • 139
  • 1
  • 3
1

If you have installed GitHubDesktop in Windows 10, then press Ctrl + '. or in the menu go to Repository>Open in command prompt.

In case git is not installed in your machine, you should get a prompt to install git.(I came to know from this that GitHubDesktop and git are different applications). Install git, close your command prompt and open it again.

You can test your installation by typing in git at the command prompt.

Venkat
  • 11
  • 1
0

You can install chocolatey. It's like apt-get in Linux, you can install using the command line. Run Command Prompt as Administrator and type choco install git and you'll be able to install git devoted to the command line.

Rico
  • 139
  • 1
0

as of now, with win 1909 and using Git-2.24.0.2-64-bit installer the process is very friendly towards user configuration. Seems like the earlier problems may now be catered for.

david
  • 1
  • 1