如何使用Node.js删除远程分支?

时间:2017-09-07 16:40:22

标签: node.js git

我目前正在使用nodegit来运行我的git命令,除了删除远程分支外,它已经适用于所有目标。如果需要,我不介意使用另一个npm包来执行此操作,但我更愿意使用nodegit。

基本上,我想要一个可以在终端

中执行与此命令相同的功能
$ git push -d <branch_name>

我希望能够写出如下内容:

function delete_remote_branch(repo, branch_name, callback) {
  repo.getRemote('origin').then(function(remote) {
    repo.getBranch(branch_name).then(function(reference) {
      // delete the branch
      repo.push("-d :"+reference, branch_name).then(function(error_code) { 
        if(error_code) {
          return callback(error_code)
        }
        return callback(null)
      })
    })
  })
}

remote.push的文档位于:http://www.nodegit.org/api/remote/#push

任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:1)

将空src引用推送到原始分支。

remote.push(':refs/heads/my-branch');