Skip to main content

Quickstart

To get up and running quickly, look at the following examples.

info

There are plenty of other methods exposed from the various classes that are not shown here.

Single Actions Per-Commit

import { ClientFactory } from "git-filesystem";

const client = new ClientFactory().getClientForProvider(
"github", // Or "gitlab" or "bitbucket". This is the only time you need to know what provider you're dealing with
"username",
"access-token",
"user-agent-name"
);

const repository = client.getRepository("repository-name");

const filePath = "file/path.txt";

await repository.createFile(filePath, "File content\n"); // This creates a commit

const fileContent = await repository.readFile(filePath);
const updatedFileContent = (fileContent += "\nNew data\n");

await repository.updateFile(filePath, updatedFileContent); // This creates a commit

await repository.deleteFile(filePath); // This creates a commit

Multiple Actions Per-Commit

import { ClientFactory } from "git-filesystem";

const client = new ClientFactory().getClientForProvider(
"github", // Or "gitlab" or "bitbucket". This is the only time you need to know what provider you're dealing with
"username",
"access-token",
"user-agent-name"
);

const repository = client.getRepository("repository-name");

const commitBuilder = repository.createCommitBuilder();

commitBuilder.createFile("one.txt", "file content");

let fileContent = await commitBuilder.readFile("two.txt");
fileContent += "\n\nNewData";
commitBuilder.updateFile("two.txt", fileContent);

commitBuilder.deleteFile("three.txt");

await commitBuilder.createCommit(); // This creates a commit that affects 3 different files