How to detach "git gui" started in "Git bash" on Windows?
Asked Answered
L

5

8

For example,

  1. I start "git bash";
  2. I navitage to certian directory;
  3. I start git gui&;
  4. I close the console window or press Ctrl+C.

Git-gui's window disappears. Even if I used git gui&disown. Even if it is not in foreground when I pressed Ctrl+C.

How to properly detach git gui from Windows console?

Limp answered 2/4, 2013 at 12:2 Comment(1)
Please, consider adding the 'msys' tag or the likes, as git-bash is the same repackaged and the same techniques apply to your case.Idealize
I
4

To the benefit of the others I will give a more general answer related to both git bash and msys bash.

Solution 1: Detach without stdout

Assume you want to detach the app:

"C:\Program Files\MyApp\MyApp.exe"

which does not output any info you want to retrieve to stdout (or stderr).
use in your Windows bash shell:

cmd //c start //D "C:\\Program Files\\MyApp"  MyApp.exe arg1 arg2 

MyApp will run in a separate window and closing the calling bash shell will not affect it (by and large like a Linux daemon).

As noted, you can't read app messages unless they are dialog messages, therefore this solution fits to GUI applications. Anyway, if MyApp.exe is instead a Windows batch file like MyApp.cmd, it will call its cmd.exe host and log there: in short you will read outputs for the .cmd/.bat case.

Mac-like users

The cmd.exe window will flash-out for an instant. If this is not such cool for you(r users), in the above line replace cmd with cmdow, NirCmd or the likes.

Solution 2: Detach with stdout

If you want to read logs to stdout and stderr, use:

cmd //c start cmd //k  "C:\\Program Files\\MyApp\\MyApp" arg1 arg2 

This alternative is mostly advised if MyApp is a console application. Now you get a daemon with a "home". MyApp will run hosted by the second cmd.exe and you will see here its output.
For a GUI app you end out with two windows: MyApp window and the calling cmd window.

In both cases, exiting MyApp doesn't mean closing the cmd window; while closing the cmd window will only close MyApp console.

If the flashing punch strikes you, here you only need to replace the first cmd, the second is your daemon's visbile home.

Solution 3: Detach document centric applications

Some documents are closely related to some processing applications, via a mechanism resembling the Linux shebang syntax, but based on Windows' registry; so you open the document without calling the related application.

This behaviour can be emulated in bash and even in a detached style.

As for apps not needing to output to stdout and stderr, opening MyApp.doc with:

cmd //c start //D "C:\\Program Files\\MyApp"  MyApp.exe  "Path\\to\\MyApp.doc"

can be simplified to:

cmd //c start //D "Path\\to" MyApp.doc

As for apps needing stdout and stderr output,

cmd //c start cmd //k  "C:\\Program Files\\MyApp\\MyApp" "Path\\to\\MyApp.doc"

can be reduced to:

cmd //c start cmd //k  "Path\\to\\MyApp.doc"
Idealize answered 30/12, 2013 at 16:26 Comment(2)
While this is a nice and comprehensive answer, It does not seem to have much to do with the original question about git gui.Hellbox
@Hellbox I have adapted the answer to above to actually answer the git gui case, see my answer https://mcmap.net/q/1295239/-how-to-detach-quot-git-gui-quot-started-in-quot-git-bash-quot-on-windowsStirling
H
3

The following command works for me from "git bash":

git gui </dev/null >/dev/null 2>&1 &

I tried Ctrl+C, Ctrl+D and simply closing the console window. git gui stayed open in all cases.

Hellbox answered 30/9, 2015 at 13:27 Comment(2)
This is perfect and is the only one that worked right for me. What is going on here and why does it work?Zouave
@Zouave I believe that under Windows, the child's input and output streams somehow stay connected to the parent's. So when the parent exits, the streams are closed, killing the child. This command redirects standard input (</dev/null), standard output (>/dev/null) and the error stream (2>&1) to /dev/null, effectively detaching them from the parent. This seems to be enough to leave the child running when the parent exits.Hellbox
B
2

If the gitgui is already started, you can disown the job so that it doesn't end with the console:

disown -h <jobid>

If you want to do it when you start Git GUI (so you just launch and forget) there is nohup but for an unknown reason it's not in the binaries distributed by MsysGit

Bagman answered 2/4, 2013 at 12:5 Comment(2)
I disown the job (at jeast it no longer present in jobs command output). I type exit. Bash leaves, console window stays open. I close console window. Git-GUI's window disappears.Limp
Also: I disown the job in git bash. It is not listed in jobs output. But Ctrl+C still kills git-gui. The question is not how to disown a job in bash, but how to do it in Windows.Limp
G
2

Based on Antonio's answer I have figured out the following recipe:

cmd //c start //D "C:\Program Files\Git\bin" "wish.exe" "C:\Program Files\Git\libexec\git-core\git-gui"

It works, as can be tested by pressing Ctrl-D in the shell. The shell closes properly and git gui continues to work.

Drawback: this solution ignores the current directory and opens git gui in the C:\Program Files\Git\bin directory, not in the current directory.

One may argue that git gui on Windows remembers recent repositories so it's only a click away. True, but the question is: how to get a detached git gui in the current directory...

I have tried a few variants to fix the drawback, but nothing truly satisfying.

The ones below always ask what to open git gui with. Choosing "C:\Program Files\Git\bin\wish.exe" in the file selector works but has to be done every time.

cmd //c start //D "E:\\escapedwindowsstyle\\path\\to\\my\\git\\repo\\" "C:\\Program Files\\Git\\bin\\wish.exe" "C:\\Program Files\\Git\\libexec\\git-core\\git-gui"

cmd //c start "C:\\Program Files\\Git\\bin\\wish.exe" "C:\\Program Files\\Git\\libexec\\git-core\\git-gui"

Can anyone understand what happens and/or improve on that ?

Gonzalogoo answered 18/11, 2014 at 19:41 Comment(0)
H
1

In Git for Windows 2.25, simply typing

git-gui

opens the GUI for the current working directory, completely detached. (Note the hyphen).

Hookup answered 11/2, 2020 at 1:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.