Monday, September 3, 2012

Git on Windows, MSysGit Context Menu, and Git Bash

Well, as I mentioned in my last post, installing Git on a Windows machine can be a bit of a hassle, and if you're not careful during the installation (like me) you can end up with a context menu which is cluttered with Git commands that you'll rarely use unless you use Git for every file on your computer....

Here's a quick forum post which describes how you can clear those nasty context menu options out of your Windows Explorer context menu.

http://stackoverflow.com/questions/2459763/how-do-i-remove-msysgits-right-click-menu-options

Now, one of those commands (Git Bash) which opens the Git shell at the current folder location, is extremely useful. Unless you plan on using TortoiseGit for everything in your file system, you probably want to have it, because starting up the Git Bash from your start menu and then navigating to the folder you want is a pain in the butt.

CMD Solution



Well the obvious answer is to add Git to your path. For me, this was:

D:\Program Files (x86)\Git\bin

If you have Cygwin installed and you have Cygwin's version of Git installed (which is probably out of date), you definitely want to make sure that the Git path appears before the Cygwin path. For me, this looks something like:

D:\Program Files (x86)\Git\bin;D:\cygwin\bin;

One caveat: Git will incessantly annoy you with warnings that the terminal is not fully functional. Don't know what to do about that. If you can live with it, then you don't need the following solution.

Cygwin Solution (Hack)



If you've got Cygwin installed I've got a solution for you.

Cygwin's shell and Git Bash operate in entirely different environments but they treat paths similarly (using the Unix-style forward slashes as path delimiters and using the drive letter as part of the path).

If you add Cygwin to your PATH (on my box, D:\cygwin\bin), you can use those Unix tools from the Windows command shell (not just in your Cygwin Terminal environment). The particular tool we're interested in is the "pwd" command.

  • Navigate to your Git repo on disk.

For me this is E:\Users\Doug\Dropbox\Classes\12f\cs371p-oop\projects\cs371p-collatz

  • Shift-Right-Click and select "Open command window here" (see below)
  • Type pwd at your prompt, to get the directory name you're currently in according to Cygwin.

E:\Users\Doug\Dropbox\Classes\12f\cs371p-oop\projects\cs371p-collatz>pwd

/cygdrive/e/Users/Doug/Dropbox/Classes/12f/cs371p-oop/projects/cs371p-collatz

  • Copy the part starting with your drive letter (e.g. /c/, or /e/ in my case)
  • Run "Git Bash" from your Start Menu
  • Type "cd " and paste the path you copied. Hit Enter and you should see something like the following:

Doug@DEFIANT ~
$ cd /e/Users/Doug/Dropbox/Classes/12f/cs371p-oop/projects/cs371p-collatz

Doug@DEFIANT /e/Users/Doug/Dropbox/Classes/12f/cs371p-oop/projects/cs371p-collatz (master)
$

  • Congratulations, you're now exactly where you want to be, in your Git Bash, and you're ready to Git away.

Yes it's convoluted but you should be fine as long as you keep your command window open while you're working. Otherwise you'll have to go through the whole process again.

Okay fine, it's definitely more fun to hack around with things like this than to actually use them. I'm thinking that I'll work on a general solution based on the below section.

General Solution to Context Menu



I haven't quite figured out an actual solution to the context menu problem yet, but I'm thinking the following article may yield a solution after some study:

http://www.howtogeek.com/howto/windows-vista/how-to-clean-up-your-messy-windows-context-menu/

Basically, what I want is to get rid of most of the context menu options and be left with just "Git Bash", which only appears when you "Shift-Right-Click," like when you want to launch a command window at the current location:


I'll give that a shot later. Maybe...

No comments:

Post a Comment