user3242205 user3242205 - 1 year ago 61
Python Question

how to pull, push with remote branch

I'm trying to automate a change process which currently creates source code that gets manually pushed to Git. I'm trying to wrap that code using GitPython:

from git import *

# create the local repo
repo = Repo.init("/tmp/test/repo", bare=True)
assert repo.bare == True

# check status of active branch

# clone the remote repo
remote_repo = repo.clone("http://user:pass@git/repo.git")

# compile source code into repository
# ...

# track untracked files

# commit changes locally
repo.commit("commit changes")

# push changes to master

When I try running this, I get

Traceback (most recent call last):

File "", line 33, in

repo.commit("commit changes")

BadObject: 636f6d6d6974206368616e676573

The script is able to pull the remote repository, but fails on commit. Is there a better approach to this?


Some of the functions you are using may not work the way you expect them to. Generally, Repo methods are not the equivalent of the git sub-command with the same name.

If you are trying to clone a remote repository, this can be achieved in a single line:

repo = Repo.clone_from("http://user:pass@git/repo.git", "/tmp/test/repo")

See the API Reference for more information on how to use GitPython.