GitSharp/Examples
From eqqon
(Difference between revisions)
m (→Init) |
(→Using git commands) |
||
Line 1: | Line 1: | ||
+ | == Playing around with git's objects == | ||
+ | === Repository === | ||
+ | Opening an existing git repository | ||
+ | {{code|var repo<nowiki>=</nowiki>new Repository("path/to/repo")}} | ||
+ | |||
+ | === Branch === | ||
+ | Get the current branch | ||
+ | {{code|var branch<nowiki>=</nowiki>repo.CurrentBranch<br> | ||
+ | Console.WriteLine("Current branch is "+branch.Name}} | ||
+ | |||
+ | Another way to get the current branch | ||
+ | {{code|repo.Head}} | ||
+ | |||
+ | Get master branch | ||
+ | {{code|var master <nowiki>=</nowiki> new Branch(repo, "master");}} | ||
+ | |||
+ | Get the abbreviated hash of the last commit on master | ||
+ | {{code|master.CurrentCommit.ShortHash}} | ||
+ | |||
+ | |||
== Using git commands == | == Using git commands == | ||
=== Init === | === Init === | ||
Initializing a new repository in the current directory (if GID_DIR environment variable is not set) | Initializing a new repository in the current directory (if GID_DIR environment variable is not set) | ||
{{code|Git.Commands.Init();}} | {{code|Git.Commands.Init();}} | ||
+ | |||
Initializing a new repository in the specified location | Initializing a new repository in the specified location | ||
{{code|Git.Commands.Init("path/to/repo");}} | {{code|Git.Commands.Init("path/to/repo");}} | ||
+ | |||
Initializing a new repository with options | Initializing a new repository with options | ||
{{code|<nowiki> | {{code|<nowiki> |
Revision as of 18:51, 4 October 2009
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();