Need help with SwiftGit2?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

528 Stars 129 Forks MIT License 498 Commits 51 Opened issues


Swift bindings to libgit2

Services available


Need anything else?

Contributors list


Build Status Carthage compatible GitHub release Swift 5.3.x

Swift bindings to libgit2.

let URL: URL = ...
let result =
switch result {
case let .success(repo):
    let latestCommit = repo
        .flatMap {

switch latestCommit {
case let .success(commit):
    print("Latest Commit: \(commit.message) by \(")

case let .failure(error):
    print("Could not get commit: \(error)")

case let .failure(error): print("Could not open repository: (error)") }


SwiftGit2 uses value objects wherever possible. That means using Swift’s

s and
s without holding references to libgit2 objects. This has a number of advantages:
  1. Values can be used concurrently.
  2. Consuming values won’t result in disk access.
  3. Disk access can be contained to a smaller number of APIs.

This vastly simplifies the design of long-lived applications, which are the most common use case with Swift. Consequently, SwiftGit2 APIs don’t necessarily map 1-to-1 with libgit2 APIs.

All methods for reading from or writing to a repository are on SwiftGit’s only

. This highlights the failability and mutation of these methods, while freeing up all other instances to be immutable
s and

Required Tools

To build SwiftGit2, you'll need the following tools installed locally:

  • cmake
  • libssh2
  • libtool
  • autoconf
  • automake
  • pkg-config
brew install cmake libssh2 libtool autoconf automake pkg-config

Adding SwiftGit2 to your Project

The easiest way to add SwiftGit2 to your project is to use Carthage. Simply add

github "SwiftGit2/SwiftGit2"
to your
and run
carthage update

If you’d like, you can do things the ~~hard~~ old-fashioned way:

  1. Add SwiftGit2 as a submodule of your project’s repository.
  2. Run
    git submodule update --init --recursive
    to fetch all of SwiftGit2’s depedencies.
  3. Add
    to your project’s Xcode project or workspace.
  4. On the “Build Phases” tab of your application target, add
    to the “Link Binary With Libraries” phase. SwiftGit2 must also be added to a “Copy Frameworks” build phase.
  5. If you added SwiftGit2 to a project (not a workspace), you will also need to add the appropriate SwiftGit2 target to the “Target Dependencies” of your application.

Building SwiftGit2 Manually

If you want to build a copy of SwiftGit2 without Carthage, possibly for development:

  1. Clone SwiftGit2
  2. Run
    git submodule update --init --recursive
    to clone the submodules
  3. Build in Xcode


We :heart: to receive pull requests! GitHub makes it easy:

  1. Fork the repository
  2. Create a branch with your changes
  3. Send a Pull Request

All contributions should match GitHub’s Swift Style Guide.


SwiftGit2 is available under the MIT license.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.