Skip to content
Michael Maxwell edited this page Jan 5, 2021 · 4 revisions

Checkout a branch or paths to the working tree

Checkout to existing branch by name

Git

$ git checkout <branch>

libgit2sharp

using (var repo = new Repository("path/to/your/repo"))
{
    var branch = repo.Branches[branchName];

    if (branch == null)
    {
        // repository return null object when branch not exists
        return null;
    }

    Branch currentBranch = Commands.Checkout(repo, branch);
}