Skip to content

Commit 19c2e04

Browse files
committed
Added an example on how to checkout a remote branch.
1 parent 320238b commit 19c2e04

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

examples/checkout-remote-branch.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var nodegit = require("../");
2+
var path = require("path");
3+
4+
var remoteBranchName = "REMOTE-BRANCH-NAME";
5+
6+
nodegit.Repository.open(path.resolve(__dirname, "../.git"))
7+
.then(function(repo) {
8+
9+
return repo.getHeadCommit()
10+
.then(function (targetCommit) {
11+
return repo.createBranch(remoteBranchName, targetCommit, false);
12+
})
13+
.then(function (reference) {
14+
return repo.checkoutBranch(reference, {});
15+
})
16+
.then(function () {
17+
return repo.getReferenceCommit(
18+
"refs/remotes/origin/" + remoteBranchName);
19+
})
20+
.then(function (commit) {
21+
nodegit.Reset.reset(repo, commit, 3, {});
22+
});
23+
24+
}).done(function() {
25+
console.log("All done!");
26+
});

0 commit comments

Comments
 (0)