Search code examples
pythongitgit-configgitpython

how do I emulate read and update git global config file using gitPython?


I want to reads git global config file using git config --list, so I can use to read and update the global config file ?


Solution

  • This will give you the ~/.gitconfig type config:

     globalconfig = git.GitConfigParser([os.path.normpath(os.path.expanduser("~/.gitconfig"))], read_only=True)
    

    That's more or less what gitpython itself does, except it also uses "system" and "repo" level configs (where system is "/etc/gitconfig"), see

     def _get_config_path(self, config_level):
    

    and

    def config_reader(self, config_level=None):
    

    in git/base.py in the source of gitpython