Last active
August 29, 2015 14:23
-
-
Save copygirl/64826fc93b5c33db6621 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cloneUrl = ...; | |
var branchName = ...; | |
var git = Git.Init().SetDirectory(Location).Call(); | |
Repository = git.GetRepository(); | |
// Original code in question works, is shorter, | |
// but this is most likely the "proper" way to do it. | |
var config = Repository.GetConfig(); | |
RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); | |
remoteConfig.AddURI(new URIish(cloneUrl)); | |
// May use * instead of branch name to fetch all branches. | |
// Same as config.SetString("remote", "origin", "fetch", ...); | |
remoteConfig.AddFetchRefSpec(new RefSpec( | |
"+refs/heads/" + Settings.Branch + | |
":refs/remotes/origin/" + Settings.Branch)); | |
remoteConfig.Update(config); | |
config.Save(); | |
git.Fetch().Call(); | |
git.BranchCreate().SetName(branchName).SetStartPoint("origin/" + branchName) | |
.SetUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).Call(); | |
git.Checkout().SetName(branchName).Call(); | |
// To update the branch: | |
git.Fetch().Call(); | |
git.Reset().SetRef("origin/" + branchName).Call(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment