Skip to content

Instantly share code, notes, and snippets.

@SunboX
Created May 17, 2018 10:10
Show Gist options
  • Save SunboX/33fc17db1c95443d6be17f5dd01e0ce0 to your computer and use it in GitHub Desktop.
Save SunboX/33fc17db1c95443d6be17f5dd01e0ce0 to your computer and use it in GitHub Desktop.
import * as Git from "nodegit";
const signature = Git.Signature.create("Foo bar", "foo@bar.com", 123456789, 60); // http://www.nodegit.org/api/signature/
const files: string[] = [path.resolve(__dirname, "./tmp/xxxx/file1.ts"), path.resolve(__dirname, "./tmp/xxxx/file2.ts")];
// open repository - maybe not necessary, because you already have a reference
//let repo = await Git.Repository.open(path.resolve(__dirname, "./tmp/xxxx/.git"));
// Create a new branch on head
let commit = await repo.getHeadCommit();
await repo.createBranch("new-branch-name", commit, true); // http://www.nodegit.org/api/repository/#createBranch
// commit
await repo.createCommitOnHead(files, signature, signature, "commit message");
// get the remote we want to push to - maybe not necessary, because you already have a reference
//let remote = Git.Remote.lookup(repo, "origin")
// push
await remote.push(["refs/heads/master:refs/heads/master"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment