GitPython unable to set the git config username and email
Asked Answered
R

2

7

I am writing a python script that uses GitPython(https://gitpython.readthedocs.io/en/stable/) to commit my local files to a remote repository. After making the edits to my files, I set the vaue of username and email as shown in the following snippet:

      repo = git.Repo.init("my local clone path")
      repo.config_writer().set_value("name", "email", "myusername").release()
      repo.config_writer().set_value("name", "email", "myemail").release()
      repo.git.add("filename")
      repo.git.commit("filename")
      repo.git.push("my remote repo url")

I always encounter the following error:

 stderr: '
*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

Even though I have set my username and password using config_writer() function as mentioned here: http://gitpython.readthedocs.io/en/stable/tutorial.html#handling-remotes

Any suggestions on how to fix this will be highly appreciated.

Rickets answered 30/4, 2018 at 16:23 Comment(0)
K
19

set_value destinations are incorrect here.

repo.config_writer().set_value("name", "email", "myusername").release()
repo.config_writer().set_value("name", "email", "myemail").release()

These lines have to be like following:

repo.config_writer().set_value("user", "name", "myusername").release()
repo.config_writer().set_value("user", "email", "myemail").release()
Kerry answered 30/4, 2018 at 16:32 Comment(1)
How can I set git secret here ?Deandra
M
-2

on using this

repo.config_writer().set_value("user", "name", "myusername").release()
repo.config_writer().set_value("user", "email", "myemail").release()

i got the below error

"config_writer() missing 1 required positional argument: 'self'."

i resolved it using

os.system("git config --global user.name \"firstname lastname\"")
os.system("git config --global user.email \"[email protected]\"")
Marciamarciano answered 19/5, 2020 at 5:37 Comment(1)
You have a problem with the repo object. It should be an instance of git.RepoBrelje

© 2022 - 2024 — McMap. All rights reserved.