gitpython returns 'git push --porcelain origin' returned with exit code 128
<p>I'm trying to push a new git repo upstream using gitpython module. Below are the steps that I'm doing and get an error 128.</p>

<pre><code># Initialize a local git repo
init_repo = Repo.init(gitlocalrepodir+"%s" %(gitinitrepo))

# Add a file to this new local git repo
init_repo.index.add([filename])

# Initial commit
init_repo.index.commit('Initial Commit - %s' %(timestr))

# Create remote
init_repo.create_remote('origin', giturl+gitinitrepo+'.git')

# Push upstream (Origin)
init_repo.remotes.origin.push()
</code></pre>

<p>While executing the push(), gitpython throws an exception:</p>

<pre><code>'git push --porcelain origin' returned with exit code 128
</code></pre>

<p>Access to github is via SSH. </p>

<p>Do you see anything wrong that I'm doing?</p>

<p>You need to capture the output from the git command.</p>

<p>Given this Progress class:</p>

<pre><code>class Progress(git.RemoteProgress):
    def __init__( self, progress_call_back ):
        self.progress_call_back = progress_call_back
        super().__init__()

        self.__all_dropped_lines = []

    def update( self, op_code, cur_count, max_count=None, message='' ):
        pass

    def line_dropped( self, line ):
        if line.startswith( 'POST git-upload-pack' ):
            return

        self.__all_dropped_lines.append( line )

    def allErrorLines( self ):
        return self.error_lines() + self.__all_dropped_lines

    def allDroppedLines( self ):
        return self.__all_dropped_lines
</code></pre>

<p>You can write code like this:</p>

<pre><code>progress = Progress()

try:
    for info in remote.push( progress=progress ):
        info_callback( info )

    for line in progress.allDroppedLines():
        log.info( line )

except GitCommandError:
    for line in progress.allErrorLines():
        log.error( line )

    raise
</code></pre>

<p>When you run with this you will still get the 128 error, but you will also have the output og git to explain the problem.</p>

python gitpython