Reputation: 385
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?
Upvotes: 26
Views: 101304
Reputation: 3251
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.
- 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
orgit config --list --global
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 ~
orecho $HOME
- Command Prompt :
echo %USERPROFILE%
- Powershell :
echo $HOME
orecho $env:USERPROFILE
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"
Upvotes: 49
Reputation: 1329082
git config --global --edit => git config --global edit
(Then exit vim, which is the usual default)
So the "--edit
" part will change with Git 2.46 (Q3 2024), batch 4: the operation mode options (like "--get") the "git config command
"(man) uses have been deprecated and replaced with subcommands (like "git config get
"(man)).
See commit 7b91d31, commit 3cbace5, commit 15dad20, commit 3418e96, commit 95ea69c, commit 00bbdde, commit 4e51389, commit 1497050, commit fee3796, commit 9dda6b7, commit daa3325, commit 8415507, commit 424a29c, commit a78b462 (06 May 2024) by Patrick Steinhardt (pks-t
).
(Merged by Junio C Hamano -- gitster
-- in commit fe3ccc7, 15 May 2024)
builtin/config
: introduce "list" subcommandSigned-off-by: Patrick Steinhardt
While git-config(1) has several modes, those modes are not exposed with subcommands but instead by specifying action flags like
--unset
or--list
.
This user interface is not really in line with how our more modern commands work, where it is a lot more customary to say e.g.git remote
(man) list.
Furthermore, to add to the confusion, git-config(1) also allows the user to request modes implicitly by just specifying the correct number of arguments.
Thus,git config foo.bar
(man) will retrieve the value of "foo.bar
" whilegit config foo.bar baz
will set it to "baz
".Overall, this makes for a confusing interface that could really use a makeover.
It hurts discoverability of what you can do with git-config(1) and is comparatively easy to get wrong.
Converting the command to have subcommands instead would go a long way to help address these issues.One concern in this context is backwards compatibility.
Luckily, we can introduce subcommands without breaking backwards compatibility at all.
This is because all the implicit modes of git-config(1) require that the first argument is a properly formatted config key.
And as config keys must have a dot in their name, any value without a dot would have been discarded by git-config(1) previous to this change.
Thus, given that none of the subcommands do have a dot, they are unambiguous.To retain backwards compatibility we only conditionally use subcommands and will fall back to the old syntax in case no subcommand was detected.
This should help to transition to the new-style syntax until we eventually deprecate and remove the old-style syntax.
So:
builtin/config
: introduce "get
" subcommandSigned-off-by: Patrick Steinhardt
Introduce a new "
get
" subcommand to git-config(1).
Please refer to preceding commits regarding the motivation behind this change.
git config
now includes in its man page:
'git config get' [<file-option>] [<display-option>] [--includes] [--all] [--regexp=<regexp>] [--value=<value>] [--fixed-value] [--default=<default>] <name>
git config
now includes in its man page:
get
Emits the value of the specified key. If key is present multiple times in the configuration, emits the last value. If
--all
is specified, emits all values associated with key. Returns error code 1 if key is not present.
git config
now includes in its man page:
'git config <name>'
Replaced by
git config get <name>
.
--get <name> [<value-pattern>]
Replaced by
git config get [--value=<pattern>] <name>
.
--get-all <name> [<value-pattern>]
Replaced by
git config get [--value=<pattern>] --all --show-names <name>
.
--get-regexp <name-regexp>
Replaced by
git config get --all --show-names --regexp <name-regexp>
.
--get-urlmatch <name> <URL>
Replaced by
git config get --all --show-names --url=<URL> <name>
.
--get-color <name> [<default>]
Replaced by
git config get --type=color [--default=<default>] <name>
.
Upvotes: 1
Reputation: 257
Open Git Bash.
Enter the command below:
git config --global --edit
Press 'i' to enable edit -- i.e i
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>
Press - esc button.
Now cursor will move at bottom.
enter :wq
and press the Enter button to exit. i.e :wq
Verify the detail by using:
git config --list
Note: Windows system, except commands may be different
Upvotes: 13