Set Git to use Sublime Text for commit messages

Whenever I set up a new computer for development, one of the first things I do is tell terminal not to use Vim when asking me for commit messages.

I find Vim painful and one of the worst things about it is that even the command to close it is unintuitive. So I never want to find myself stuck in it and having to Google it yet again.

Below are the code snippets to past into your terminal. Note that, on Windows at least, you’ll need to make sure that path to the Sublime Text executable is correct. Just open a My Computer window and browse to that location to check or copy it.

If you want to use another text editor, you can do so also, you’ll just need to change everything within the single quotation marks. The other elements within the double quotation marks are still required and are explained below.

On Mac

git config --global core.editor "'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' -w --launch-or-new-window"

On Windows

git config --global core.editor "'c:/program files/sublime text 3/sublime_text.exe' -w --launch-or-new-window"

Now, when you type git commit Sublime text will open with a commit file ready for you. Simple type your message and save it, and then when you close the file or sublime text, terminal will continue.

You can also close without saving and the terminal will recognise that as you choosing to abort the commit.

What this code does…

  • It edits the git global configuration settings to provide it the editor that should be used.
  • It passes in the path to that editor.
  • -w This tells the terminal to wait until the sublime text file has been closed to continue. This is important and the process won’t work without this.
  • –launch-or-new-window This tells sublime text to open a new window if it’s already open, or just open if it’s closed.

    The last one is what I’ve found to be my preference, as if I sometimes close sublime without saving, I don’t want the next commit to open another copy of the same window (sometimes building up lots of windows on top of each other).

    -n does a similar thing, but forces a new window every time—Which sometimes causes the issue described above.

    Not include -n or –launch-or-new-window will mean that if a commit file is already open in sublime from previously it will also you if you want to reload it. This slows you down slight as you can’t just start typing. Note that with the –launch-or-new-window one, this still happens if you closed sublime without saving, but I find it helpful to let me know there’s a duplicate window floating around.

That’s it!

Thanks…

I also dissect and speculate on design and development.
Digging into subtle details and implications, and exploring broad perspectives and potential paradigm shifts.
Check out my conceptual articles on Substack or find my latest below.


You can also find me on Threads, Bluesky, Mastodon, or X for more diverse posts about ongoing projects.

My latest articles

Designing immersive experiences

In traditional cinema, TV, or even the more modern phone screen, there’s limited screen real-estate. But removing that limitation creates a design problem…

The future is not prompt engineered

Let’s not pretend the importance of prompt engineering is ubiquitous. The most prevalent power of generative AI is in the way it adapts to us, not the other way around…

The typography of dates, times, & filenames

A deep dive into carefully considered date formatting, line length and general typography attributes of filenames…


Author:

Date:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.