Published on

Git Automation with Node.js


If you plan on interacting with/automating Node.js then simple-git might be a good choice.

With the help of this package, we can easily interact with Git


npm install simple-git

Code Snippet

import simpleGit from 'simple-git';
// const simpleGit = require("simple-git");
const git = simpleGit().clean(simpleGit.CleanOptions.FORCE);

const createNewBranch = (branchName, startPoint = "origin/main") => {
  return git
    .exec(() => console.log("Creating new branch branch..."))
    .checkoutBranch(branchName, startPoint)
    .exec(() => console.log("done."));

createNewBranch("newBranchName", startPoint);

Happy interacting-with git!