Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a5ae9bd

Browse files
committed
Creates repo.branch function, closes github-tools#36
Commit with tweaks from @itsjoesullivan, see pull github-tools#37 Combined if statement, got rid of whitespace and made note of default to master in README.md
1 parent 8b43038 commit a5ae9bd

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ Fork repository. This operation runs asynchronously. You may want to poll for `r
6161
repo.fork(function(err) {});
6262
```
6363

64+
Create new branch for repo. You can omit oldBranchName to default to "master".
65+
66+
```js
67+
repo.branch(oldBranchName, newBranchName, function(err) {});
68+
```
69+
6470
Create Pull Request.
6571

6672
```js

github.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,24 @@
354354
_request("POST", repoPath + "/forks", null, cb);
355355
};
356356

357+
// Branch repository
358+
// --------
359+
360+
this.branch = function(oldBranch,newBranch,cb) {
361+
if(arguments.length === 2 && typeof arguments[1] === "function") {
362+
cb = newBranch;
363+
newBranch = oldBranch;
364+
oldBranch = "master";
365+
}
366+
this.getRef("heads/" + oldBranch, function(err,ref) {
367+
if(err && cb) return cb(err);
368+
that.createRef({
369+
ref: "refs/heads/" + newBranch,
370+
sha: ref
371+
},cb);
372+
});
373+
}
374+
357375
// Create pull request
358376
// --------
359377

0 commit comments

Comments
 (0)