function checkoutLocalBranch(simpleGit, branches, title, cb) { if (!branches[title]) { simpleGit.checkoutLocalBranch(title, function (e) { if (e) console.log(e) if (!e && cb) cb() }) } else { simpleGit.checkout(title, function (e) { if (e) console.log(e) if (!e && cb) cb() }) } } exports.autoCheckoutLocalBranch = function (simpleGit, title, cb, errcb) { simpleGit.checkIsRepo(function (err, ok) { if (ok) { simpleGit.branchLocal(function (err, branchSummary) { if (!err) { if (branchSummary.current == "master") { checkoutLocalBranch(simpleGit, branchSummary.branches, title, function () { cb() }) } else { simpleGit.checkout("master", function () { checkoutLocalBranch(simpleGit, branchSummary.branches, title, function () { cb() }) }) } console.log(branchSummary) } else { console.log(err) } }) } else { if (errcb) errcb(err) } }) }