A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://stackoverflow.com/questions/51047785/git-archive-remote-command-using-gitpython below:

git archive --remote command using GitPython

This question is quite old, but I came across the same problem, so here's my solution:

import git
import shutil

url = 'ssh://url-to.my/repo.git'
remote_ref = 'master'
tmprepo = 'temprepo'
tarball = 'contents.tar'

try:
    repo = git.Repo.init(tmprepo)
    repo.create_remote('origin', url)
    repo.remote().fetch(remote_ref)

    with open(tarball, 'wb') as f:
        repo.archive(f, f'remotes/origin/{remote_ref}', path=None)
    print('Success')
finally:
    shutil.rmtree(tmprepo)

A few notes:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4