Is there implementation of Git in pure Python?
I know that this question is rather old, but I just thought I would add this for the next guy. The accepted answer mentions Dulwich and mentions that it is rather low-level (which is also my opinion). I found gittle which is a high-level wrapper around Dulwich. It's rather easy to use.
$ pip install gittle
Examples (taken from the project's README.md):
from gittle import Gittle
repo_path = '/tmp/gittle_bare'
repo_url = 'git://github.com/FriendCode/gittle.git'
repo = Gittle.clone(repo_url, repo_path)
repo = Gittle.init(path)
# Get list of objects
repo.commits
# Get list of branches
repo.branches
# Get list of modified files (in current working directory)
repo.modified_files
# Get diff between latest commits
repo.diff('HEAD', 'HEAD~1')
# Stage single file
repo.stage('file.txt')
# Stage multiple files
repo.stage(['other1.txt', 'other2.txt'])
# Do the commit
repo.commit(name="Samy Pesse", email="samy@friendco.de", message="This is a commit")
repo = Gittle(repo_path, origin_uri=repo_url)
# Authentication with RSA private key
key_file = open('/Users/Me/keys/rsa/private_rsa')
repo.auth(pkey=key_file)
# Do pull
repo.pull()
repo = Gittle(repo_path, origin_uri=repo_url)
# Authentication with RSA private key
key_file = open('/Users/Me/keys/rsa/private_rsa')
repo.auth(pkey=key_file)
# Do push
repo.push()
# Create branch off master
repo.create_branch('dev', 'master')
# Checkout the branch
repo.switch_branch('dev')
# Create an empty branch (like 'git checkout --orphan')
repo.create_orphan_branch('NewBranchName')
# Print a list of branches
print(repo.branches)
# Remove a branch
repo.remove_branch('dev')
# Print a list of branches
print(repo.branches)
These are just the parts (again pulled from the project's README.md) which I think would be most common use-cases. You should check out the project yourself if you need more than this.