157

When I'm using Git on Mac and need to do a rebase, the Vim editor kicks in by default. I would prefer Nano – could someone please explain how to reconfigure Git to make it use Nano for rebase?

1
  • 9
    I prefer nano too, I am no masochist.
    – Rolf
    Sep 22, 2017 at 10:31

3 Answers 3

255

git config --global core.editor "nano"

More information here:

https://git-scm.com/book/en/Customizing-Git-Git-Configuration

1
  • This is manna from cli heaven 😝 🙌 🎉
    – gdibble
    May 25, 2021 at 19:25
36

If you want to use nano as your editor for all things command line, add this to your bash_profile:

export EDITOR=/usr/bin/nano

This is assuming you're using the system nano. If not, edit to suit where your nano lives (e.g. /usr/local/bin, /opt/local/bin)

Remember to source your bash_profile after setting this or open a new terminal window for the settings to work...

3
4

I just learned a moment ago that there (on OSX anyway) is a file at /Users/<USER_NAME>/.gitconfig

$ nano /Users/bob/.gitconfig

Then you should see something like this:

[user]
    email = [email protected]
    name = Bob Sandwich
[core]
    editor = nano
[merge]
    tool = vscode
[mergetool "vscode"]
    cmd = "code --wait "
[diff]
    tool = vscode
[difftool "vscode"]
    cmd = "code --wait --diff  "

After seeing that structure, you can intuitively understand something like (ie: core.editor):

git config --global core.editor "nano"
5
  • Love the detail here, ty 👍
    – gdibble
    May 25, 2021 at 19:27
  • WTF are you doing there? "sudo nano <file in your $home>"? And only for reading a file? To which you've got access anyway? How about... "cat <file in your $home>"?
    – alexs77
    Jun 18, 2021 at 7:33
  • 1
    If you use sudo nano .gitconfig, on the chance that the file doesn't exist and is created, it will be owned by root. Since it is unnecessary, drop the sudo. May 30, 2023 at 16:44
  • @AlexanderSkwar How would cat .gitconfig help someone edit the file? May 30, 2023 at 16:44
  • In my experience cat file causes an 'undesirable' scroll event when the file is larger than the viewport, but I think you should use your preferred method of inspecting; using cat guarantees inability to edit while observing--part of a well balanced immutability diet. (also I removed the sudo; thanks)
    – agm1984
    Jun 1, 2023 at 17:15

You must log in to answer this question.