18

I have Ruby and GIT installed on my windows box. To run GIT commands I am utilizing the GIT Bash. To run Ruby commands I am using the command line.

I have not been successful running GIT commands from the CMD line nor can I seem to run Ruby commands from inside the GIT Bash. I would love to be able to run commands for both GIT and Ruby from the GIT Bash (ideal) or at the least from the CMD line.

What is the best way to go about this?

Joseph U.
  • 4,457
  • 10
  • 41
  • 47

6 Answers6

26

I run git commands from the CMD session all the time.

Make sure your PATH environment variable includes the 'cmd' directory from a msysgit distro:

Path=C:\Path\To\Git\1.7.1\cmd

If not, add it in your session:

set PATH=%PATH%;C:\Path\To\Git\1.7.1\cmd

and you are done. Git and Ruby commands in your CMD shell.

The reverse (Ruby commands) is possible in a Git bash, by adding to the PATH a value like /c/path/to/Ruby/186-27/bin

http://img842.i_mageshack.us/img842/8749/gitbashruby.png

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    VonC answer is the best one. Usage of cmd git wrapper is the safest approach to Git usage. Also, for having Ruby available in your setup, I recommend you install RubyInstaller packages. – Luis Lavena Aug 06 '10 at 22:52
9

To elaborate on VonC's answer of making Ruby available in Git-Bash.

All you have to do is add the path to your Ruby bin folder in your windows environment variables. It doesn't have to be in the format /c/path/to/ruby, it can be C:\Ruby193\bin.

Step by step for Windows 7:

  1. Start
  2. Search programs and files (default textbox after hitting the Start icon), Search for 'environment'
  3. Select 'edit the system environment variables'
  4. Click 'Environment Variables' (bottom right of the form)
  5. Add to the 'System Variables' 'PATH' the following ';C:\Ruby193\bin' (without the single quotes)
  6. Restart your shell

Make sure to close your git-bash shell and restart it to pick up the new environment variable.

Rots
  • 5,506
  • 3
  • 43
  • 51
  • This doesn't seem to work for me. Though 'PATH' is in the user variables and 'Path' is in the system variables. I've tried both. Neither are working. Any thoughts? I added `;C:\Ruby21-x64\bin` to the end of the variables. – gin93r Oct 06 '14 at 18:12
  • 1
    Ok I got it. Apparently running it from a shortcut holds onto the old PATH variables - until machine restart. Launching git-bash from the start menu worked fine. – gin93r Oct 06 '14 at 18:34
1
  • Go to My Computer -> Properties -> Advanced system settings -> Environment Variables

  • Add a New System variable. Variable name = RUBY_BIN. Variable value = C:\Ruby193\bin (path may vary).

  • Add a New System variable. Variable name = MSYSGIT_BIN. Variable value = C:\msysgit\bin (path may vary).

  • Append ;%RUBY_BIN%;%MSYSGIT_BIN% to Path variable, under System variables.

  • Restart shell.

This will allow you to run ruby, git or sh (Git Bash) commands from Command Prompt, as well as Ruby from Git Bash.

Timofey Drozhzhin
  • 4,416
  • 3
  • 28
  • 31
0

The combined answer for VonC and Rots helped me to achieve the desired results.

However, since I was not familiar with editing environment variables, I must have accidentally overwritten the path for my nodejs files.

As a result my solution included adding the ruby path and the nodejs path to my user variables instead of the system.

I'm using a Windows 7 machine.

Jannaee
  • 51
  • 5
0

while installing ruby installer, select the option "Add ruby executables to your path" . Then all git/ruby commands will run from git bash.

0

My personal setup uses msysgit and tortoisegit. I've found that using TortoiseGit's Pageant manager for the keys lets me use everything from any command line, including powershell. The only annoyance is I have to have pageant running with the keys added, which seem to clear on every reboot. Fortunately I don't reboot often.

Karl
  • 6,035
  • 5
  • 30
  • 39
  • For my purposes I also have a Heroku gem installed that wants to run GIT commands. But until I implement the PATH solution mentioned above the Heroku command won't run from the GIT bash and the GIT commands issued by the Heroku command won't run from the command line. Seems like the Path solution should have me happily running things from the GIT bash which will be ideal. – Joseph U. Aug 06 '10 at 21:21