Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Capturing Ctrl-C in MINGW-Bash shell #1248
git version 2.13.3.windows.1
This is specific to MINGW64
NOTE: This problem does NOT occur with the MINGW32 package.
Microsoft Windows [Version 6.1.7601]
Path Option: Cmd
This is not specific to GIT, but rather for the GIT for windows installation and MSYS.
I am running a self created C# program, which attempts to capture a Ctrl-C event and cancel using an event handler like so:
Main program flow:
Console.CancelKeyPress += new ConsoleCancelEventHandler(CheckForConsoleCancel);
I expected the program to reach my event handler allowing me to clean up my program before exit.
The program exits without calling my handler.
This problem DOES NOT happen with a windows CMD prompt, nor SH.exe provided with the installation.
I remember reading before that this was a problem with an older version of MSYS's BASH shell, but I can't find the link anymore... to my knowledge it was fixed there awhile ago.
referenced this issue
Aug 16, 2017
referenced this issue
Aug 31, 2017
I kind of had the same problem where commands weren't killed when i hit CRTL+C.
This is how it came and how i solved it:
On my fresh windows installation i installed Git-2.14.2-64-bit. Then i faces the issue that commands (docker logs etc) keep on sending to console after i killed them through CRTL+C.
I reinstalled the older version which i know was working (Git-2.10.2-64-bit) on my old windows installation. Still same problem.
Then i found in an issue in mintty tacker a comment which leaded to a probably wrong cygwin dependency.
And exactly this is the case here. Uninstalling of Git-2.14.2-64-bit didn't wipe C:/Program Files/Git completely. Cygwin libs stayed.
So probably these broken libs were used also with the working version Git-2.10.2-64-bit.
Then i did manually clean git folder and reinstalled Git-2.10.2-64-bit and voila no issues anymore.
I guess also for updating to newer versions, old cygwin files stay and some users never face this problem. Obviously fresh installation leads into problems.
I'm was running 2.14.2.windows.1 and in the whole MINGW64 Git Bash MinTTY shell on Windows 10 and running into the same or similar issue where CTRL+C didn't seem to be sending the correct signal.
In my case I'm starting up an http server using Node and closing it with CTRL+C. If I start the server using just
If I start the same server using
This bug doesn't show up on a Windows 7 box or on a Linux Mint box running Git 2.7.4. In both cases, two processes are spawned, but CTRL+C from the command line will close both and free up the port.
Installing 2.15.1.windows.2 didn't solve the problem. My installation of Git was in
@PhilWim Do you have a link to that comment in the mintty tracker?
Thanks @PhilWim Uninstalling, wiping Program Files/Git folder and installing version 2.10.2-64 helped.
@Broutard - I suggest this:
I have a script called portkill.sh
Add it to your path, then run with
Sadly, this introduces regressions for fixes we made in the meantime.
Oh wow. This elicits quite a negative reaction here. Probably not what you expected.
If you want anybody to work for you, to solve your problem, you might want to take a different approach.
As to the original report: this should be addressed by our recent change in how processes are killed when the user presses Ctrl+C.
If it still does not work for you in Git for Windows v2.16.2, you may want to consider selecting the "ConHost" option rather than the "MinTTY" option as terminal for the Git Bash. That should fix the issue, too.
I cannot say that I am happy about the enthusiasm to leave all the hard work to me. Nevertheless, I think I have a fix for this now. It should hit https://wingit.blob.core.windows.net/files/index.html within 24h.
added a commit
Apr 23, 2018
added a commit
Apr 23, 2018
The newest snapshot at https://wingit.blob.core.windows.net/files/index.html should fix this. Please test.
Wow... I've been trying to figure out why ctrl-C was taking forever to register in my git bash for windows when running webpack-dev-server (a problem I've had for the past year) and found this issue, and as luck would have it find that it was fixed two days ago! I'll have to wait for it to get to a 'maintained' release state but I'm glad it's been fixed. I've been going through the comments as well as the author's (Johannes) summary of the history of this issue and want to thank him for taking this challenge and fixing it when others in the community would not. @dscho, perhaps an alternative perspective on this would help... perhaps nobody else was up to the task, and you are the only one in this community with the technical expertise to fix it; the Linus Torvalds or Richard Stallman of Git for Windows, so to speak. Whatever the reason, you are indeed the man... thank you!