-
Notifications
You must be signed in to change notification settings - Fork 890
git branch
Norbert Rozmus edited this page Apr 5, 2017
·
14 revisions
$ git branch
using (var repo = new Repository("path/to/your/repo"))
{
foreach(Branch b in repo.Branches.Where(b => !b.IsRemote))
{
Console.WriteLine(string.Format("{0}{1}", b.IsCurrentRepositoryHead ? "*" : " ", b.FriendlyName));
}
}
$ git branch --contains <commit>
using (var repo = new Repository("path/to/your/repo"))
{
const string commitSha = "5b5b025afb0b4c913b4c338a42934a3863bf3644";
foreach(Branch b in ListBranchesContainingCommit(repo, commitSha))
{
Console.WriteLine(b.Name);
}
}
private IEnumerable<Branch> ListBranchesContainingCommit(Repository repo, string commitSha)
{
var localHeads = repo.Refs.Where(r => r.IsLocalBranch);
var commit = repo.Lookup<Commit>(commitSha);
var localHeadsContainingTheCommit = repo.Refs.ReachableFrom(localHeads, new[] { commit });
return localHeadsContainingTheCommit
.Select(branchRef => repo.Branches[branchRef.CanonicalName]);
}
$ git branch develop
using (var repo = new Repository("path/to/your/repo"))
{
repo.CreateBranch("develop"); // Or repo.Branches.Add("develop", "HEAD");
}
$ git branch other HEAD~1
using (var repo = new Repository("path/to/your/repo"))
{
repo.CreateBranch("other", "HEAD~1"); // Or repo.Branches.Add("other", "HEAD~1");
}
To be done
To be done
To be done
To be done
using (var repo = new Repository("path/to/your/repo"))
{
repo.Branches.Remove("BranchToDelete");
}
$ git branch --edit-description
var description = "branch description"
using (var repo = new Repository("path/to/your/repo"))
{
var key = string.Format("branch.{0}.description", branch);
repo.Config.Set(key, description.Replace(Environment.NewLine, string.Empty)); // set description
repo.Config.Unset(key); // remove description
}