Git Checkout and Pull through Lib2GitSharp

I am trying to build an application that periodically scans the commit history on various Git branches and reports on the authors and various details about the commit messages. I have started using LibGit2Sharp for this. It has been great for accessing the commits themselves, but I have run into a snag when trying to update the repository.

Every time my task runs, I need to get the most recent changes from the remote repository. My understanding is I need to checkout the local branch that tracks the remote branch in question, then perform a fetch or pull. I am attempting to do this in my app as follows:

// Get the branch
var localBranch = repo.Branches[localbranchName];

// Switch to this branch
if (!localBranch.IsCurrentRepositoryHead)

// Do a pull to get latest
var result = repo.Network.Pull(signature, new PullOptions());

However, I always get the following exception when running repo.Checkout(localBranch);

LibGit2Sharp.LibGit2SharpException: Failed to mmap. No data written: Not enough storage is available to process this command.
  at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in c:\Git\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 160
  at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) in c:\Git\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 178
  at LibGit2Sharp.Core.Proxy.git_checkout_tree(RepositorySafeHandle repo, ObjectId treeId, GitCheckoutOpts& opts) in c:\Git\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 295
  at LibGit2Sharp.Repository.CheckoutTree(Tree tree, IList`1 paths, IConvertableToGitCheckoutOpts opts)...

When I manually checkout that branch in Git Bash and run my program (bypassing the need for the the checkout command) it then fails on the call to Pull with the same exception.

There’s not a whole lot about this error out there but everything I’ve seen so far has resulted in answers to the extent of “Your repository is just too large for the library to handle.” The repository I am using is a fair-sized enterprise repository, but these commands execute in the console pretty quickly. I’m wondering now if I need to wrap my console in a handler and execute the checkout and pull directly through the CLI (yuck).

Any thoughts?

  • Need to get the details of the modified files in GitPull method in cake script
  • LibGit2Sharp Find what files were updated/added/deleted after pull
  • Wait until Commit-Operation is finished
  • Get files modified/added/removed from a commit in LibGit2Sharp
  • origin/master VS origin/HEAD
  • How can I add a TreeEntry to a Commit's Tree collection?
  • How to find all commits having a particular parent?
  • LibGit2Sharp has archived diff files
  • One Solution collect form web for “Git Checkout and Pull through Lib2GitSharp”

    Apologies for this. There have been a handful of changes to libgit2 and LibGit2Sharp to deal with memory usage, and better handling of memory mapping, especially with large (or numerous) packfiles.

    You will see these improvements in the next release of LibGit2Sharp. Until then, installing a prerelease package from should resolve this issue.

    Git Baby is a git and github fan, let's start git clone.