Skip to content
A JavaScript implementation of Git.
TypeScript JavaScript
Branch: master
Clone or download
Pull request Compare This branch is 82 commits ahead, 9 commits behind creationix:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Git implemented in EcmaScript

Online demo showing how to pull, commit and push changes


This basic example shows how to do low-level manipulation of an in-memory repository

import { Mode, mix } from '@es-git/core';
import MemoryRepo from '@es-git/memory-repo';
import objectMixin from '@es-git/object-mixin';
import saveAsMixin from '@es-git/save-as-mixin';
import loadAsMixin from '@es-git/load-as-mixin';

async function test(){
  // Create the repository in memory and
  // enhance it using three mixins
  class Repo extends mix(MemoryRepo)
                    .with(loadAsMixin) {}

  // Create an instance of the repository
  const repo = new Repo();

  // Save a text file in the repo with the contents `hello`
  const hash = await repo.saveText('hello');

  // Save a folder with one file, the one we created above
  const tree = await repo.saveTree({
    'file.txt': {
      mode: Mode.file,

  // Commit the file and folder to the repo
  const commitHash = await repo.saveCommit({
    author: {
      name: 'Tim Caswell',
      email: '',
      date: new Date()
    committer: {
      name: 'Marius Gundersen',
      email: '',
      date: new Date()
    message: 'initial commit',
    parents: []

  // Point the master branch to the commit
  await repo.setRef('refs/heads/master', commitHash);

  // Get the hash that the master branch points to
  const refHash = await repo.getRef('refs/heads/master');
  if(!refHash) throw new Error('branch does not exist');

  // Get the commit (the hash of the tree and the message) using the hash
  const {tree: treeHash, message} = await repo.loadCommit(refHash);
  console.log(message); // `initial commit`

  // Get the hash to the `file.txt' file in the tree
  const {'file.txt': {hash: fileHash}} = await repo.loadTree(treeHash);

  // Get the content of the file as a string
  const content = await repo.loadText(fileHash);
  console.log(content) // `hello`



These are the core storage packages. They all implement IRawRepo. Pick one that fits your project, and enhance it with the mixins.


These mixins add features to the repo. Some of them depend on other mixins, so the order in which the mixins are applied is significant.

Other packages

The mix package provides a useful mixin function for extending the base repo

Relationship to JS-Git

This project is a fork of JS-Git, refactored and rewritten in TypeScript. See #132 for more information.

You can’t perform that action at this time.