Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I edit the .git / config file from the git terminal?

Tags:

git

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?

like image 698
sinfryd95 Avatar asked Sep 05 '25 17:09

sinfryd95


2 Answers

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.

Idealy a vi editor opens up by default if no editor is configured by the user.

If the user is presented with a vi editor, in that case the user will have to :

  • Go into insert mode by hitting i key, you should see -- INSERT -- displayed at the bottom of the screen
  • Make changes to the contents
  • Once done, you need to save your changes and exit the editor. For this go into command mode by hitting Esc key; you should see the -- INSERT -- word has been cleared. Now type :wq (stands for write and quit) and hit return key(Enter key). Your config changes ahve been saved.
  • To verify you changes type git config --list or git config --list --global

If you don't want to use the command

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.

To find your $HOME, you can use below commands:

  • Git Bash : echo ~ or echo $HOME
  • Command Prompt : echo %USERPROFILE%
  • Powershell : echo $HOME or echo $env:USERPROFILE

Configuring default editor for git

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"
like image 123
Asif Kamran Malick Avatar answered Sep 07 '25 08:09

Asif Kamran Malick


  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

like image 27
Maulik Boghara Avatar answered Sep 07 '25 06:09

Maulik Boghara