I started fighting this problem in this question. I split it off because I realized that it was a different issue that doesn't involve gitpython, but rather git alone.
I have a python script that involves pushing and pulling to a local gitlab instance that must be run as root. The .git/config looks like this:
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = git@gitlab.our.instance.name:my-name/repo-name.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
I have discovered that whenever I run a git pull or git clone as root from gitlab, it requires the git@gitlab.our.instance.name password as if it was ssh-ing into the host. As you can see in the remote url, all remote operations are done over ssh protocol, not https.
Is this a configuration issue with gitlab? Something I don't know about git or ssh? I must run this script as sudo, so for now I'm working on a way to run the git pull not as root.
Another note for people with similar issues and are seeing error: cannot open .git/FETCH_HEAD: Permission denied while not running as sudo, either delete .git/FETCH_HEAD or change it's ownership away from root and it should execute as normal. This is because git pull involves git fetch, but as it is not successful, it leaves behind an empty FETCH_HEAD owned by root:root, which can't written to by unprivileged users.