Swiftpack.co -  way-to-code/git-macOS as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A high-level swift framework based on the GIT macOS command line utility
.package(url: "https://github.com/way-to-code/git-macOS.git", from: "2.0.0")


A high-level swift framework to work with git command line in macOS

Git is a high-level swift framework based on the command line Git utility in macOS.


  • Cloning remote repositories (git clone and git fetch). Including shallow clone support (--depth option);
  • Getting the list of references (branches, tags) in repositories;
  • Checking out references (git checkout);
  • Working with remotes (listing, renaming, setting urls);
  • Committing local changes and pushing to a remote repository (git commit and git push);
  • Getting log records for a repository (git log);
  • Listing pending log records (committed locally, but not pushed yet) and upcoming log records (commited on a remote, but not presented in the working copy)
  • Working with stashes (git stash);
  • Basic merge (git merge);

Git.framework has no dependencies. Just clone and build.


  • macOS 10.12+
  • Xcode 10+
  • Swift 4.2+
  • Git for Mac 2.15+


Before installing this framework, please make sure you're using the correct version of Git in your system. You can check the current version via Terminal app:

git --version
$ git version 2.15.1


To install Carthage you can use Homebrew. Use the following command in Terminal app:

$ brew update
$ brew install carthage

To integrate Git.framework into your Xcode project using Carthage, specify it in your Cartfile:

github "way-to-code/git-macOS" ~> 2.0.0

Run carthage update to build the framework and drag the built Git.framework into your Xcode project.

Swift 4.2

If you want to use Git.framework on Xcode 10.1 or lower, please use version 1.5.1

github "way-to-code/git-macOS" ~> 1.5.1


You can install Git.framework manually. Clone the project locally, build and integrate to your project as a framework

Swift Package dependency

When you want to use Git.framework as a dependency in other package, you may follow the given example:

let package = Package(
    name: "MyPackage",
    products: [
        .library(name: "myProduct", targets: ["myTarget"]),
    dependencies: [
        .package(name: "Git",
                 url: "https://github.com/way-to-code/git-macOS.git",
                 .upToNextMajor(from: "2.0.0")),
    targets: [
        .target(name: "myTarget", dependencies: [
            .product(name: "Git", package: "Git")


Read more about Git.framework in the Wiki page:

Quick examples

Simple clone

To clone a remote repository you need to create an object GitRepository

let repository = GitRepository(fromUrl: URL(string: "https://github.com/github/hub.git"))

Next, just call the clone method

try? repository.clone(atPath: "/Users/youruser/hub")

Providing credentials

You can specify credentials for repository with a help of GitCredentialsProvider. If no credentials are specified, credentials from the global macOS system git config are used by default.

let credentialsProvider = GitCredentialsProvider(username:"user", password:"****")
let repository = GitRepository(from: URL(string: "https://github.com/github/hub.git"), using: credentialsProvider)

Receiving the progress

You may keep track of the clone operation progress, by setting a delegate object on repository

let progressTracker = MyCustomObject()

let repository: GitRepository
repository.delegate = progressTracker

// implement RepositoryDelegate protocol in order to track the events
extension MyCustomObject: RepositoryDelegate {
func repository(_ repository: Repository, didProgressClone progress: String) {


Stars: 9
Last commit: Yesterday

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes


Important: Version is increased to 2.0.0 because API was changed slightly and migration is needed. Please read the information below.

Public API changes

Changed RepositoryReference.name property.

In version 1.x when name property was calculated, it returned a reference name without an addional information. For example, for refs/remotes/origin/main it returned just main and for refs/heads/main also main. This behaviour was ambiguous.

From this time a name property no longer String. It has it's own type RepositoryReferenceName that contains a various properties for getting a reference name.

Renamed methods

To better correspond Swift API Design Guidelines some methods were renamed:

  • GitRepository init(at:using:) was renamed into init(atPath:using:);
  • GitRepository init(from:using:) was renamed into init(fromUrl:using);
  • GitRepository clone(at:options:) was renamed into clone(atPath:options);
  • GitRepository createRepository(atPath:options:credentials:) was renamed into create(atPath:options:using:)

Added better handling for init method

GitRepository init method has been improved. Now instead of returning nil from initializer it throws an exception in case repository can not be initialized by some reason. In addition, the method now will check whether .git directory exists or not. When .git directory does not exist, an exception will be raised.

GitReferenceList, GitRemoteList improved

Added conformance to Sequence for GitReferenceList and GitRemoteList. Now it is possible to interate throw the list using for cycle:

let remotesList = try repository.listRemotes()

for remote in remotesList {

Migration guide to 2.0.0

Rename methods

  1. clone

    try repository.clone(at: localPath, options: options)


    try repository.clone(atPath: localPath, options: options)
  2. init

    GitRepository(from: url, using: credentialsProvider)


    try GitRepository(fromUrl: url, using: credentialsProvider)
  3. init

    GitRepository(at: path, using: credentialsProvider)


    try GitRepository(atPath: path, using: credentialsProvider)
  4. createRepository

    GitRepository.createRepository(atPath: path)


    GitRepository.create(atPath: path)

Handle RepositoryReference name changes

In case you used RepositoryReference.name property somehow you need to replace that code with the following:

let reference: RepositoryReference


let reference: RepositoryReference

You may use other properties on RepositoryReferenceName, not just localName. Please refer to the documentation of RepositoryReferenceName within the code that covers all possible cases in details.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API