43

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
user.email=myemail@email.com

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?

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
bboysupaman
  • 1,274
  • 1
  • 13
  • 20

2 Answers2

54

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    We can edit --global settings on `~/.gitconfig` i want to change global configs for git made by `git config --global user.name or user.email` simiply, using nano for ex: `nano ~/.gitconfig` edit it and save. [Reference](https://askubuntu.com/a/206459/500671) – Abdallah Okasha Jul 26 '18 at 14:22
  • 1
    @AbdallahOkasha True. I prefer using `git config` commands to avoid any mishaps while editing directly the config file. – VonC Jul 26 '18 at 14:36
  • the real bad answer. what is $HOME? is it in C:\Program Files\Git? where is path/to/git/config? why git config --local --list doesn't show my proxy setting? your answer help me if i know the answer. lol – Amir Oct 26 '19 at 22:22
  • 1
    @Amir I have edited my answer to clarify what "$HOME" would be on Windows. – VonC Oct 26 '19 at 22:28
  • @Amir And I have edited the answer to address your other question: "why `git config --local --list` doesn't show my proxy setting?" – VonC Oct 26 '19 at 22:32
  • can anyone help me with this problem https://stackoverflow.com/questions/61830920/where-to-find-the-config-directory-of-git-on-mac-os – Ken Verganio May 16 '20 at 02:41
5

Remove all custom settings:

rm ~/.gitconfig
Mohammad Fazeli
  • 648
  • 10
  • 13