0

I am trying to connect to my git repo through code wanted to create branch dynamically , using nodegit to achieve this task it is throwing an error No file or directory found.

Need help with following task with nodegit :

1- Connect to git repo by passing my credentials

2- create a branch and set that as upstream

open.js

Git.Repository.open(path.resolve(__dirname, "https://gitw.dgital-1.com/digital//myproject"))
    .then(function(repo) {
      // Create a new branch on head
      console.log("REPO", repo);
      return repo.getHeadCommit()
      .then(function(commit) {
        return repo.createBranch(
          "new-branch",
          commit,
          0);
      });
    });
hussain
  • 6,587
  • 18
  • 79
  • 152
  • rtm: https://www.nodegit.org/api/branch/#create `Branch.create(repo, "new-branch", commit)` – Lawrence Cherone Sep 15 '20 at 13:56
  • @LawrenceCherone how do we pass credentials to connect to repo i need to do that i believe to get repo details right – hussain Sep 15 '20 at 13:59
  • also it looks like you have messed up the path.. see the example: https://github.com/nodegit/nodegit/blob/master/examples/create-branch.js its pointing to a .git file, yours is not also without testing I'm not sure you can do a remote.. this tool is git binding i.e it talks to the local git install – Lawrence Cherone Sep 15 '20 at 14:01
  • prob only way is git clone -> make branch -> git push. your need ssh keys setup and use this method to push https://stackoverflow.com/questions/27564755/how-to-clone-git-repository-with-nodegit-using-ssh, there is other examples in the examples folder, could even clone from https, then change .git/config file with fs.write etc and change url to use `git@` etc if the lib doesn't support pushing back over https or no username/password facilities – Lawrence Cherone Sep 15 '20 at 14:08

0 Answers0