PushStack Docs
git-edge

Getting started

Install git-edge and perform your first object-level three-way merge.

Install

npm install git-edge isomorphic-git

isomorphic-git and git-fs-s3 (≥ 0.8) are peer dependencies — install them yourself; threeWayMerge stores its objects through git-fs-s3's withPackedWrites. git-edge works with any isomorphic-git-compatible fs, including plain node:fs, not only git-fs-s3's.

Quick start

  1. Build the { fs, gitdir, cache? } shape isomorphic-git itself expects — any compatible fs works, node:fs here.

    import fs from 'node:fs';
    
    const repo = { fs, gitdir: '/repo.git', cache: {} };
  2. Merge one ref into another. threeWayMerge resolves both refs, takes the fast-forward shortcut when possible, and otherwise merges at the tree level — no worktree involved at any point.

    import { threeWayMerge, GitMergeConflictError } from 'git-edge';
    
    try {
      const { commitOid } = await threeWayMerge(repo, 'feature', 'main', {
        authorName: 'Ada',
        authorEmail: 'ada@example.com',
      });
      console.log('merged:', commitOid);
    } catch (err) {
      if (err instanceof GitMergeConflictError) {
        console.log('conflicts in:', err.conflictingPaths);
      } else {
        throw err;
      }
    }

With git-fs-s3

Same call, backed by object storage instead of local disk — this is the pairing git-edge was extracted alongside.

import git from 'isomorphic-git';
import { createGitFs, MemoryObjectStore } from 'git-fs-s3';
import { threeWayMerge } from 'git-edge';

const fs = createGitFs(new MemoryObjectStore());
const repo = { fs, gitdir: '/repo.git', cache: {} };

await git.init({ ...repo, dir: repo.gitdir, bare: true });
// ... commits land on "feature" and "main" via git-fs-s3's fs ...
await threeWayMerge(repo, 'feature', 'main');

Neither package imports the other — they just agree on the same { fs, gitdir, cache? } shape. Swap in any isomorphic-git-compatible fs and threeWayMerge works unchanged.

Next steps

  • Reading the same repo's objects repeatedly (a commit list, a rendered diff)? See the parsed-object cache guide.
  • Running many operations against the same repo in one process? See Repo cache for isomorphic-git's own packfile cache.

On this page