70

I used to launch Git GUI within my Cygwin console without any problems, but since I updated Cygwin I've got the following error message:

$ git gui
Application initialization failed: no display name and no $DISPLAY environment variable
Error in startup script: invalid command name "tk_messageBox"
    while executing
"tk_messageBox  -icon error  -type ok  -title "git-gui: fatal error"  -message $err"
    invoked from within
"if {[catch {package require Tcl 8.4} err]
 || [catch {package require Tk  8.4} err]
} {
        catch {wm withdraw .}
        tk_messageBox \
                -icon error \
                -typ..."
    (file "/usr/lib/git-core/git-gui" line 34)

How can I solve this?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Stijn Vanpoucke
  • 1,395
  • 3
  • 15
  • 29
  • you might consider launching [Git For Windows](http://git-scm.com/download/win) , which provides git gui, using a separate non-cygwin/msys shell instead. You just have to mind your cygwin/windows paths so cygwin doesnt try to use it instead of the cygwin version, which can cause some issues. – AndrewD Feb 10 '15 at 20:25
  • @AndrewD Combining Git for Windows with Cygwin is going to be a PITA: Different filename conventions, and even different home directories (usually) so you have to manage two sets of git settings. – toolforger Sep 20 '19 at 08:51

7 Answers7

124

Cygwin's gitk and Git GUI require X11. This means you need to install some of the Cygwin X11 packages and set them up to be able to open the GUI.

This should get you up and running:

  1. Run the Cygwin installer again (download the relevant setup-*.exe again if you need to).
  2. At the package list, select to install "xinit" under the X11 category. Click next, accept all the dependencies, and install.
  3. In the Windows Start menu, you should have a new group: Cygwin-X. From there, run XWin Server.
  4. In your Cygwin shell, run export DISPLAY=:0.0.

You'll need to repeat step 3 every time you reboot your computer, and step 4 every time you open a new Cygwin shell (or just run echo "export DISPLAY=:0.0" >>~/.profile to have it run automatically whenever you create a new shell).

In the comments, it seems some people are getting errors stating 'couldn't connect to display ":0.0"'. If you get that, mouse over the X that should have appeared in your system tray (you may need to click the little up icon if the X icon has been hidden); the pop-up title should say something like "Cygwin/X Server:1.0". Use that ":1.0" (or whatever you see) as the value for DISPLAY in step 4, rather than ":0.0", making sure to include the colon.

If you have any other problems starting the X server, you will probably find you have a file called ~/.xsession-errors; check out the contents of that for what's going wrong. Also check whether you have a ~/.startxwinrc file, and try deleting it and seeing if that fixes the problem.

For the interested, the reason the X11 packages aren't installed automatically is that they're not technically needed: it's possible through somewhat convoluted means to use a different X11 server than the one Cygwin installs when you install the "xinit" package.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
me_and
  • 13,911
  • 6
  • 58
  • 93
  • 2
    The look and feel isn't what it used to be but at least it works again. Thanks! – Stijn Vanpoucke Feb 24 '12 at 08:01
  • 4
    @Stijn: Agreed. I preferred the old interface too (not least because I have a custom Windows keyboard layout which X11 can't understand). The [justification for the change](http://cygwin.com/ml/cygwin/2012-02/msg00447.html) is that Tcl/Tk (the language Git GUI and Gitk and so forth run on) has moved to X11, so to avoid being stuck with an obsolete Tcl/Tk, Cygwin had to make the same change. – me_and Feb 24 '12 at 09:41
  • You're right about “not technically needed”. I know people who prefer(red) to use Exceed. (Why? I don't know…) – Donal Fellows Feb 26 '12 at 16:12
  • 8
    I added the following line to my bash profile to eliminate having to execute step 3 every day. If this works for you too, you may wish to edit the answer. "startxwin >/dev/null 2>&1 &" – Mark F Guerra May 18 '12 at 14:17
  • 2
    Did you find a way to automatically hide the xterm when launching the XWin Server? – Stijn Vanpoucke Jun 12 '12 at 08:50
  • 5
    @StijnVanpoucke: Yes: run `touch ~/.startxwinrc` from a bash shell. I've answered that fully over on Super User: http://superuser.com/q/435768/21002 – me_and Jun 12 '12 at 13:08
  • 1
    Just a NOTE: If you have tried to run `gitk` before installing the X11 Server there will likely be a file called ~/.gitk on your system. Delete it as this contains parameters that will cause gitk to error with `Error in startup script: unknown color name "SystemButtonFace"` – RiggsFolly Nov 06 '13 at 11:27
  • Nice steps. BTW: we can test the setting using xclock – camino Mar 12 '15 at 17:20
  • 1
    FYI - The display isn't always `:0.0`. If yours doesn't work after these steps, hover over the XWin icon in your taskbar and use whatever it says. In my case `:1.0`. Also, "X-start-menu-icons" did not exist for me, something else must have replaced it. – Eric Fossum Feb 08 '16 at 17:53
  • step 5. set `enable_xauth=0` in `\bin\startxwin` if you are getting "Authorization required, but no authorization protocol specified" – TT-- Jul 19 '18 at 16:39
  • I already have the Xming Server installed (for use with PuTTY). Is there a way to get Cygwin to work with Xming rather than having to install XWin Server? – Jugdish Apr 13 '20 at 18:33
  • @Jugdish Welcome to Stack Overflow! You're going to get a much better response if you ask that as a brand new question rather than as a comment here; I don't know the answer off the top of my head, and asking it as a new question will mean many more people who might be able to help will see it. – me_and Apr 17 '20 at 11:46
9

After spending more time than I'd care to admit, I managed to find a working solution to execute gitk from my Cygwin shell. I couldn't get any of the instructions with starting the X server to work reliably, and in the end, the solution was pretty simple.

The largest caveat is needing to have Git for Windows installed, the download for that can be found here.

Now for the whole running gitk part. Git for windows includes a cmd folder, that has a gitk.cmd windows command file. That's all you need to call to have gitk open.

$ [path-to-git]/cmd/gitk.cmd

On my system the Git path is in "C:\Program Files (x86)\Git", so the command would look like this:

$ "/cygdrive/c/Program Files (x86)/Git/cmd/gitk.cmd"

In my ~/.bash_profile file I've added a function to handle that call which looks like this:

gitk() {
  "/cygdrive/c/Program Files (x86)/Git/cmd/gitk.cmd"
}
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
David Kartik
  • 454
  • 4
  • 9
8

Avoid X11 and add Git GUI support to Cygwin

If you want to avoid X11 (and who wouldn't?):

  1. Install Git for Windows (non-cygwin) http://git-scm.com/download/win
  2. Open its command shell C:\Program Files (x86)\Git\Git Bash
  3. run git gui

(Optional) If you want to stay in Cygwin to launch Git GUI, add a function in your ~/.bashrc to do it. The only caveat is do not name the function git because of recursion and confusion with arguments, and the fact that you're Git for Windows shell may also be adding the same function when it starts. You may also run into path issues so be careful about setting up your paths correctly.

# Call Git GUI from Git For Windows path with `ggui`
    gg() {
    command "/cygdrive/c/Program Files (x86)/Git/bin/git" gui  2>/dev/null;


    }

When you're done editing your .bashrc, refresh your settings:

source ~./bashrc

and then simply:

gg
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
AndrewD
  • 3,661
  • 2
  • 26
  • 29
  • If you name the function git-gui instead of gg, it will open when you type the command `git gui` - git will use that as an extension. – configurator Jan 09 '17 at 10:07
6
echo "export DISPLAY=:0.0" >>~/.profile

or

echo "export DISPLAY=:0.0" >>~/.bash_profile

in my case

Gunther Struyf
  • 11,083
  • 2
  • 31
  • 56
tititou36
  • 69
  • 1
  • 1
2

After following the four steps given by me_and and tititou36, you may still have issues of the XWin just die after you started the XwinServer.

The reason is it relies on a Cygwin terminal/console, which is the host, and the Xwin dies if there is no Cygwin console.

The solution for this is:

Start a Cygwin console (you can make it automatically start by putting mintty command into the file .startxwinrc under your Cygwin home directory).

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
2

Here is what worked for me:

cat >> ~/.bash_profile <<< "export DISPLAY=:0.0"

From the Cygwin package manager, do the following:

install xorg-server and some xorg fonts, xorg-x11-fonts-Type1 especially.

Next, create a link to the Windows font folders for Git GUI to use:

ln -s /cygdrive/c/Windows/Fonts /usr/share/fonts/win-fonts

Close the Cygwin terminal and open again then type

startxwin &> /dev/null &

git gui &
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
smac89
  • 26,360
  • 11
  • 91
  • 124
1

Based on AndrewD's answer: Don't use Cygwin's git, but use Windows Git's gitk and git gui. In other words, uninstall the git-gui and gitk packages from Cygwin (if installed). Then which gitk should point to the Windows file, not the Cygwin binary in /usr/bin.

C-Otto
  • 4,941
  • 3
  • 25
  • 60