bboysupaman
bboysupaman

Reputation: 1334

Git: Easiest way to reset git config file

I am finally getting around to learning git. However, I unwisely started messing around with it awhile back (before I really knew what I was doing) via Sourcetree. Now that I'm trying to go through it, I have a pretty large list of settings. When I input:

git config --list

I get the following result:

core.excludesfile=~/.gitignore
core.legacyheaders=false
core.quotepath=false
core.pager=less -r
mergetool.keepbackup=true
push.default=simple
color.ui=auto
color.interactive=auto
repack.usedeltabaseoffset=true
alias.s=status
alias.a=!git add . && git status
alias.au=!git add -u . && git status
alias.aa=!git add . && git add -u . && git status
alias.c=commit
alias.cm=commit -m
alias.ca=commit --amend
alias.ac=!git add . && git commit
alias.acm=!git add . && git commit -m
alias.l=log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'
alias.ll=log --stat --abbrev-commit
alias.lg=log --color --graph --pretty=format:'%C(bold white)%h%Creset -%C(bold green)%d%Creset %s %C(bold green)(%cr)%Creset %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
alias.llg=log --color --graph --pretty=format:'%C(bold white)%H %d%Creset%n%s%n%+b%C(bold blue)%an <%ae>%Creset %C(bold green)%cr (%ci)' --abbrev-commit
alias.d=diff
alias.master=checkout master
alias.spull=svn rebase
alias.spush=svn dcommit
alias.alias=!git config --list | grep 'alias\.' | sed 's/alias\.\([^=]*\)=\(.*\)/\1\     => \2/' | sort
include.path=~/.gitcinclude
include.path=.githubconfig
include.path=.gitcredential
diff.exif.textconv=exif
credential.helper=osxkeychain
core.excludesfile=/Users/myusername/.gitignore_global
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=/Applications/SourceTree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
user.name=My Name
[email protected]

And that seems like more than what I want to start with since the tutorial that I'm working through doesn't pull all of that up.

Is there a way to "Reset" the config file to a default state?

Upvotes: 48

Views: 295416

Answers (2)

VonC
VonC

Reputation: 1328522

Note that git config --list does display both

  • the system (<path/to/git/config>), meaning where Git has been installed.
    (By default, on Windows: C:\Program Files\Git)
  • global ($HOME/.gitconfig).
    On Windows, $HOME would be %USERPROFILE%
  • and local (path/to/repo/.git/config) settings.

To see the ones you have added to your repo:

git config --local --list

To remove multiple values:

git config [<file-option>] --unset-all name [value_regex]
git config [<file-option>] --remove-section name

For instance: git config --local --remove-section alias would get rid of the aliases.

That is a bit more precise that just getting rid of the .git/config file.


why git config --local --list doesn't show my proxy setting?

Typically because a proxy setting could have been added for all repository, globally.

 git config --global --list

That would be in ~/.gitconfig or %USERPROFILE%\.gitconfig.


Note: if you want to remove a specific value (not a regex), use Git 2.30 (Q1 2021)

Various subcommands of "git config"(man) that takes value_regex learn the "--literal-value" option to take the value_regex option as a literal string.

See commit c902618 (25 Nov 2020) by Junio C Hamano (gitster).
See commit 3f1bae1, commit c90702a, commit fda4394, commit d156719, commit 2076dba, commit 247e2f8, commit 504ee12 (25 Nov 2020) by Derrick Stolee (derrickstolee).
(Merged by Junio C Hamano -- gitster -- in commit a10e784, 08 Dec 2020)

config: add --fixed-value option, un-implemented

Signed-off-by: Derrick Stolee

The 'git config'(man) builtin takes a 'value-pattern' parameter for several actions.

This can cause confusion when expecting exact value matches instead of regex matches, especially when the input string contains metacharacters. While callers can escape the patterns themselves, it would be more friendly to allow an argument to disable the pattern matching in favor of an exact string match.

Add a new '--fixed-value' option that does not currently change the behavior.

The implementation will be filled in by later changes for each appropriate action. For now, check and test that --fixed-value will abort the command when included with an incompatible action or without a 'value-pattern' argument.

The name '--fixed-value' was chosen over something simpler like '--fixed' because some commands allow regular expressions on the key in addition to the value.

git config now includes in its man page:

--fixed-value

When used with the value-pattern argument, treat value-pattern as an exact string instead of a regular expression. This will restrict the name/value pairs that are matched to only those where the value is exactly equal to the value-pattern.


Warning: "git config --value=foo --fixed-value section.key newvalue"(man)barfed when the existing value in the configuration file used the valueless true syntax, which has been corrected with Git 2.47 (Q4 2024), batch 4.

See commit 615d2de (01 Aug 2024) by Taylor Blau (ttaylorr).
(Merged by Junio C Hamano -- gitster -- in commit 4cf2f1b, 14 Aug 2024)

config.c: avoid segfault with --fixed-value and valueless config

Reported-by: Han Jiang
Signed-off-by: Taylor Blau

When using --fixed-value with a key whose value is left empty (implied as being "true"), 'git config'(man) may crash when invoked like either of:

$ git config set --file=config --value=value --fixed-value \
    section.key pattern
$ git config --file=config --fixed-value section.key value pattern

The original bugreport bisects to 00bbdde (builtin/config: introduce , 2024-05-06, Git v2.46.0-rc0 -- merge listed in batch #4) (builtin/config: introduce "set" subcommand, 2024-05-06), which is a red-herring, since the original bugreport uses the new 'git config' set invocation.

The behavior likely bisects back to c90702a ("config: plumb --fixed-value into config API", 2020-11-25, Git v2.30.0-rc0 -- merge listed in batch #11), which introduces the new --fixed-value option in the first place.

Looking at the relevant frame from a failed process's coredump, the crash appears in config.c::matches() like so:

(gdb) up
#1  0x000055b3e8b06022 in matches (key=0x55b3ea894360 "section.key", value=0x0,
    store=0x7ffe99076eb0) at config.c:2884
2884          return !strcmp(store->fixed_value, value);

where we are trying to compare the --fixed-value argument to value, which is NULL.

Avoid attempting to match --fixed-value for configuration keys with no explicit value.
A future patch could consider the empty value to mean "true", "yes", "on", etc.
when invoked with --type=bool, but let's punt on that for now in the name of avoiding the segfault.

Upvotes: 60

Mohammad Fazeli
Mohammad Fazeli

Reputation: 817

Remove all custom settings:

rm ~/.gitconfig

Upvotes: 9

Related Questions