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?
asked Mar 1, 2017 at 17:01
Hakan Baba
2,0756 gold badges26 silver badges43 bronze badges
1 Answer 1
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")
answered Mar 5, 2017 at 19:39
Hakan Baba
2,0756 gold badges26 silver badges43 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
Hakan Baba
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.
0andriy
How to do this without
Repo object? Like getting global settings.Michael H.
That's not yet possible, see github.com/gitpython-developers/GitPython/issues/775
Ernesto Elsäßer
Quick update: To access global settings directly, you can now use
git.config.GitConfigParser().get_value(...) (see github.com/gitpython-developers/GitPython/pull/950)