Using Windows Explorer as a Git IDE

I have a couple of different stationary computers. A custom-built PC running Windows, an iMac G3 running Mac OS 9 and an old HP microtower running Alpine Linux, acting as a home server of sorts. Out of all these, I spend most of my time on the Windows PC. I use Windows for the majority of my work, including a large part of the programming that I do.

Even though I mainly use Windows, most of my web/software development is grounded in or at least inspired by Unix in some way: most obviously, I use Git, which is a tool designed for the Unix shell. This turns out to be a rather awkward match: on the one hand, I use Windows Explorer to manage the files; on the other hand, I have a command prompt open to manage the repository.

For my workflow, it would be much better if the Git commands were integrated into Explorer itself. So I added what amounts to the following code to my AutoHotKey script:

GroupAdd, Explorer, ahk_class CabinetWClass
GroupAdd, Explorer, ahk_class ExploreWClass

#IfWinActive ahk_group Explorer

!a::Run, % "cmd /c cd "qp()" & git add "qip()" && git status & pause"
!c::Run, % "cmd /c cd "qp()" & git commit & pause"
!+c::Run, % "cmd /c cd "qp()" & git commit --amend & pause"
!f::Run, % "cmd /c cd "qp()" & git diff & pause"
!+f::Run, % "cmd /c cd "qp()" & git diff "qip()" & pause"
!i::Run, % "cmd /c cd "qp()" & git diff HEAD~1 HEAD & pause"
!+i::Run, % "cmd /c cd "qp()" & git diff HEAD~1 HEAD "qip()" & pause"
!l::Run, % "cmd /c cd "qp()" & git log & pause"
!+l::Run, % "cmd /c cd "qp()" & git log "qip()" & pause"
!p::Run, % "cmd /c cd "qp()" & git push & pause"
!r::Run, % "cmd /c cd "qp()" & git reset "qip()" && git status & pause"
!s::Run, % "cmd /c cd "qp()" & git status & pause"


Explorer(hwnd := "")
ShellApp := ComObjCreate("Shell.Application")
if (hwnd = "")
WinGet, hwnd, id, A
for window in ShellApp.Windows
if (window.hwnd = hwnd)
return window
return -1

return """" Explorer().Document.Folder.Self.path """"

return """" Explorer().Document.FocusedItem.path """"

(The actual code is contained in this file, most of it near the bottom.)

This adds a bunch of hotkeys to any Explorer window:

"git add" the selected file; then "git status"
"git commit"
"git commit --amend"
"git diff"
"git diff" the selected file
"git diff", comparing the previous and current commit
"git diff" the selected file, comparing the previous and current commit
"git log"
"git log" the selected file
"git push"
"git reset" the selected file; then "git status"
"git status"

All of these hotkeys open a new command prompt window, displaying the results of the Git command, which the user can close by pressing any key.

In my experience, these hotkeys make it incalculably less bothersome to work with Git on Windows, and I think it shows how incredibly useful even very simple AutoHotKey scripts can be. If you have any suggestions on other hotkeys, please write a comment below.


Comments  •  Submit