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?

asked Mar 1, 2017 at 17:01

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")
answered Mar 5, 2017 at 19:39
Sign up to request clarification or add additional context in comments.

4 Comments

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.
How to do this without Repo object? Like getting global settings.
Quick update: To access global settings directly, you can now use git.config.GitConfigParser().get_value(...) (see github.com/gitpython-developers/GitPython/pull/950)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.