Skip to content
KindDragon edited this page Feb 27, 2013 · 2 revisions

git-symbolic-ref

Creating a symbolic reference

Git

$ git symbolic-ref i-track-for-a-living refs/heads/master

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    var symRef = repo.Refs.Create("i-track-for-a-living", "refs/heads/master");
}

Updating the target of a symbolic reference

Git

$ git symbolic-ref i-track-for-a-living refs/heads/vNext

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    var symRef = repo.Refs.UpdateTarget("i-track-for-a-living", "refs/heads/vNext");
}

Reading which branch the given symbolic reference refers to

Reading the HEAD

Git

$ git symbolic-ref HEAD

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    Console.WriteLine(repo.Head.CanonicalName));
}

Reading any symbolic reference

Git

$ git symbolic-ref i-track-for-a-living

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    Console.WriteLine(repo.Refs["i-track-for-a-living"].TargetIdentifier);
}