From b4ca7c7c57deb04add7f3c3aae8017ea95902f31 Mon Sep 17 00:00:00 2001 From: Chris Simpson Date: Thu, 11 Aug 2022 07:35:54 +0100 Subject: [PATCH] docs: Adds documentation on how to create a branch (#2541) --- docs/git-database.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/git-database.md b/docs/git-database.md index e135b139..56aba79a 100644 --- a/docs/git-database.md +++ b/docs/git-database.md @@ -1,5 +1,19 @@ # Working with the Git Database +### Create a Branch + +Branches can be created through the Git client. These are known as References. To create a reference, the first property you need is the name of the branch you want to create. You must ensure the reference starts with "refs" and contain two "/", otherwise it will be rejected. The second property is the SHA of the commit you want to branch from. This can be any commit but it must exist in the repository to be accepted. + +```csharp +var reference = new NewReference($"refs/heads/{branchName}", commit.Sha); +``` + +You can then create the Reference using the Reference.Create Api, either passing in the Repository Owner and Name or the Repository Id. +```csharp +var branch = await github.Git.Reference.Create(owner, repo, reference); +var branch = await github.Git.Reference.Create(id, reference); +``` + ### Tag a Commit Tags can be created through the GitHub API