Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Git commit

James Sconfitto edited this page Jul 29, 2013 · 5 revisions

The following examples assume you already have a repository in place to work with. If not, see git-init.

Committing to a non-bare repository

If you want to commit to a repository that is checked out to the file system, you can update the file on the file system and use the repository's Commit method.

using (var repo = new Repository("path/to/your/repo"))
{
    // Write content to file system
    var content = "Commit this!";
    File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, "fileToCommit.txt"), content);

    // Stage the file
    repo.Index.Stage("fileToCommit.txt");

    // Create the committer's signature and commit
    Signature author = new Signature("James", "@jugglingnutcase", DateTime.Now);
    Signature committer = author;

    // Commit to the repository
    Commit commit = repo.Commit("Here's a commit i made!", author, committer);
}
Clone this wiki locally