6

I have a repo initialized as

r = git.Repo.init(dirPath)

How can I get the user.email field for the git config for that repo using gitpython?

1 Answer 1

12

After looking into the source of gitpython this is one way I managed to do it.

r = git.Repo.init(dirPath)
reader = r.config_reader()
field = reader.get_value("user","email")
4
  • In case the user.email config does not exist, the get_value function may throw and exception or return a default value. The user can affect that behavior by passing a default parameter named "default" to the get_value function.
    – Hakan Baba
    Commented Mar 5, 2017 at 19:40
  • How to do this without Repo object? Like getting global settings.
    – 0andriy
    Commented Jun 19, 2018 at 15:26
  • That's not yet possible, see github.com/gitpython-developers/GitPython/issues/775
    – Michael H.
    Commented Apr 24, 2019 at 13:41
  • 1
    Quick update: To access global settings directly, you can now use git.config.GitConfigParser().get_value(...) (see github.com/gitpython-developers/GitPython/pull/950) Commented Mar 14, 2023 at 21:26

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.