GitSharp/Examples

From eqqon

< GitSharp
Revision as of 18:51, 4 October 2009 by Henon (Talk | contribs)
Jump to: navigation, search

Contents

Playing around with git's objects

Repository

Opening an existing git repository

var repo=new Repository("path/to/repo")

Branch

Get the current branch

var branch=repo.CurrentBranch
Console.WriteLine("Current branch is "+branch.Name

Another way to get the current branch

repo.Head

Get master branch

var master = new Branch(repo, "master");

Get the abbreviated hash of the last commit on master

master.CurrentCommit.ShortHash


Using git commands

Init

Initializing a new repository in the current directory (if GID_DIR environment variable is not set)

Git.Commands.Init();

Initializing a new repository in the specified location

Git.Commands.Init("path/to/repo");

Initializing a new repository with options

var cmd = new Git.InitCommand("path/to/repo") { Quiet=false, Bare=true };
cmd.Execute();