How to set Xcode as core.editor in git?

My current git config core.editor returns dreamweaver which I set up two years ago from inside the app(IIRC), and now I don't use it. I am receiving error while amending the author of the last commit.

~$ git commit --amend --author="me <my@mail>"
hint: Waiting for your editor to close the file... fatal: cannot run 
dreamweaver: No such file or directory
error: unable to start editor 'dreamweaver'

How do I set it to use Xcode? I tried

git config --global core.editor="xcode"
error: invalid key: core.editor=Xcode

And from https://stackoverflow.com/questions/53550025/git-unable-to-start-xcode-from-terminal-on-mac-os-x, even though xed launches Xcode.

$ git config --global core.editor="xed"
error: invalid key: core.editor=xed

xed -w also launches Xcode so I tried the same instead of ="xed -w" but same error.


Solution 1:

It's all about syntax sometimes :-)

git config --global core.editor 'xed -w'

Not sure whether you really want to wait for Xcode to launch each time you git commit something. Maybe vi or nano are the better options here.

Solution 2:

I would never want to do what you want, I think it's a horrible idea, but I tried to, and I succeeded!

What did I do? Easy:

  1. Open Xcode and remove the splash window from the boot (in case it could create some mayhem).

  2. Find Xcode: well, it's hard to explain how, but I found it at /Applications/Xcode.app/Contents/MacOS/Xcode.

  3. Repeat your mistake:

    $ git config core.editor=/Applications/Xcode.app/Contents/MacOS/Xcode 
    error: invalid key: core.editor=/Applications/Xcode.app/Contents/MacOS/Xcode
    $ _
    
  4. Make it right:

    $ git config core.editor /Applications/Xcode.app/Contents/MacOS/Xcode 
    $ echo $?
    0
    $ _
    
  5. Cloned a repo, made a silly change, added it to the index.

  6. git commit, tada!

Editing commit message on Xcode

If you have any issues repeating this, go back to step 4.