How do I show my global Git configuration?

后端 未结 12 2078
遇见更好的自我
遇见更好的自我 2020-12-04 04:28

I\'d like to show all configured Git sections.

I only found git config --get core.editor, and I\'d like to output everything that\'s configured globally

相关标签:
12条回答
  • 2020-12-04 04:44

    You can use:

    git config --list
    

    or look at your ~/.gitconfig file. The local configuration will be in your repository's .git/config file.

    Use:

    git config --list --show-origin
    

    to see where that setting is defined (global, user, repo, etc...)

    0 讨论(0)
  • 2020-12-04 04:44

    If you just want to list one part of the Git configuration, such as alias, core, remote, etc., you could just pipe the result through grep. Something like:

    git config --global -l | grep core
    
    0 讨论(0)
  • 2020-12-04 04:45

    You can also call git config -e to open the configuration file in your editor directly. The Git configuration file is much more readable that the -l output, so I always tend to use the -e flag.

    So to summarise:

    git config -l  # List Git configuration settings (same as --list)
    git config -e  # Opens Git configuration in the default editor (same as --edit)
    
    • Without parameters it interacts with the local .git/config.
    • With --global it interacts with ~/.gitconfig.
    • And with --system it interacts with $(prefix)/etc/gitconfig.

    (I couldn't really find what $(prefix) means, but it seems to default to $HOME.)

    0 讨论(0)
  • 2020-12-04 04:45

    You can also use cat ~/.gitconfig.

    0 讨论(0)
  • 2020-12-04 04:45

    Git 2.6 (Sept/Oct 2015) will add the option --name-only to simplify the output of a git config -l:

    See commit a92330d, commit f225987, commit 9f1429d (20 Aug 2015) by Jeff King (peff).
    See commit ebca2d4 (20 Aug 2015), and commit 905f203, commit 578625f (10 Aug 2015) by SZEDER Gábor (szeder).
    (Merged by Junio C Hamano -- gitster -- in commit fc9dfda, 31 Aug 2015)

    config: add '--name-only' option to list only variable names

    'git config' can only show values or name-value pairs, so if a shell script needs the names of set config variables it has to run 'git config --list' or '--get-regexp' and parse the output to separate config variable names from their values.
    However, such a parsing can't cope with multi-line values.

    Though 'git config' can produce null-terminated output for newline-safe parsing, that's of no use in such a case, because shells can't cope with null characters.

    Even our own bash completion script suffers from these issues.

    Help the completion script, and shell scripts in general, by introducing the '--name-only' option to modify the output of '--list' and '--get-regexp' to list only the names of config variables, so they don't have to perform error-prone post processing to separate variable names from their values anymore.

    0 讨论(0)
  • 2020-12-04 04:48

    One important thing about git config:

    git config has --local, --global and --system levels and corresponding files.

    So you may use git config --local, git config --global and git config --system.

    By default, git config will write to a local level if no configuration option is passed. Local configuration values are stored in a file that can be found in the repository's .git directory: .git/config

    Global level configuration is user-specific, meaning it is applied to an operating system user. Global configuration values are stored in a file that is located in a user's home directory. ~/.gitconfig on Unix systems and C:\Users\<username>\.gitconfig on Windows.

    System-level configuration is applied across an entire machine. This covers all users on an operating system and all repositories. The system level configuration file lives in a gitconfig file off the system root path. $(prefix)/etc/gitconfig on Linux systems. On Windows this file can be found in C:\ProgramData\Git\config.

    So your option is to find that global .gitconfig file and edit it.

    Or you can use git config --global --list.

    This is exactly the line what you need.

    0 讨论(0)
提交回复
热议问题