5

I am trying to modify the config file from the git terminal, for this, inside the repository, I have launched the command git global --edit.

An editor opens within the same terminal, my problem is, how can I save the changes and exit the editor?? Every time I make a change the editor crashes and I have to start over.

Is there a way to do it more easily outside of the terminal?

sinfryd95
  • 175
  • 1
  • 2
  • 8

2 Answers2

10

I have launched the command git global --edit

Not sure how and why that works for you. That should not have worked in the first place. To edit the config globally in editor, you should use below command :

git config --global --edit

This should open a text editor, make your changes ,save and exit the editor. That should work.

If you don't want to use the command and still want to be able to edit the git config, then locate the .gitconfig file in your home directory $HOME/.gitconfig.

NOTE: You can also change the default editor that git commands open up by executing below command in your git bash :

git config --global core.editor "<editor-name> --wait"

Replace <editor-name> with the editor of your choice which is currently installed on your system. For VS code , the command would be :

git config --global core.editor "code --wait"
Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47
  • Ok, I try that command, and how do I save the changes and exit the editor? What commands should I use? – sinfryd95 Mar 04 '21 at 13:52
  • I believe it is opening in vi editor. I can tell for windows: If that is the case, make changes to file, hit ESC, type `:wq` and hit return (the Enter key on Windows). `wq` is to save your changes and exit. just typing `:q` exits without saving. – Asif Kamran Malick Mar 04 '21 at 13:58
  • Added some useful information to my answer. Hope that will save you from future frustrations. – Asif Kamran Malick Mar 04 '21 at 14:14
  • Mention that if the editor is in a directory with a space, to enclose it in `'` such as `"'C:\Program Files\Myeditor' -multiInst -nosession"` – ΩmegaMan Oct 03 '22 at 13:50
  • You can set default editor to be Notepad++ too: `git config --global core.editor "notepad++"` (--wait is here not required). – Matt Aug 29 '23 at 07:15
4
  1. Open Git Bash.

  2. Enter the command below:

    git config --global --edit 
    
  3. Press 'i' to enable edit -- i.e i

  4. Enter or modify the user:

    For example:

    [User1] i.e can use any name like Personal, Business, other, etc..
    name = <github username>
    email = <github email>
    [User2] i.e can use any name like Personal, Business, other, etc..
    name = <github username>
    email = <github email>
    
  5. Press - esc button.

  6. Now cursor will move at bottom. enter :wq and press the Enter button to exit. i.e :wq

  7. Verify the detail by using:

    git config --list
    

Note: Windows system, except commands may be different

Ethan
  • 876
  • 8
  • 18
  • 34
Maulik Boghara
  • 129
  • 1
  • 5