A highly extensible Git implementation in pure Go.
Go Other
Latest commit 0e9dea1 Feb 27, 2017 @smola smola committed on GitHub Merge pull request #289 from ajnavarro/documentation/cache
plumbing/cache: specify units in memory size (Fix #234)
Permalink
Failed to load latest commit information.
.travis travis: fix ssh key Oct 18, 2016
_examples documentation and API improvements Feb 21, 2017
cli/go-git new srcd.works/go-git.v4 path Jan 30, 2017
config documentation and API improvements Feb 21, 2017
internal/revision Add revision implementation (#139) Feb 6, 2017
plumbing Merge pull request #289 from ajnavarro/documentation/cache Feb 27, 2017
storage documentation and API improvements Feb 21, 2017
utils Fix issue 275 (edited) (#276) Feb 22, 2017
.gitignore core: Storage.Get, switch order of args Aug 29, 2016
.travis.yml Add fast_finish flag to travis configuration Feb 23, 2017
LICENSE Update LICENSE (#174) Dec 9, 2016
Makefile travis update to 1.8 and makefile silence commands Feb 21, 2017
README.md Update README.md Feb 1, 2017
blame.go documentation changes Jan 31, 2017
blame_test.go new srcd.works/go-git.v4 path Jan 30, 2017
common.go submodule init and update implementation Feb 13, 2017
common_test.go *: update tests to meet new submodule fixture Feb 21, 2017
doc.go documentation and API improvements Feb 21, 2017
example_test.go fix example folder Feb 1, 2017
options.go documentation and API improvements Feb 21, 2017
references.go new srcd.works/go-git.v4 path Jan 30, 2017
references_test.go new srcd.works/go-git.v4 path Jan 30, 2017
remote.go submodule init implementation Feb 12, 2017
remote_test.go submodule init implementation Feb 12, 2017
repository.go documentation and API improvements Feb 21, 2017
repository_test.go documentation and API improvements Feb 21, 2017
submodule.go documentation and API improvements Feb 21, 2017
submodule_test.go submodule update implementation Feb 15, 2017
worktree.go documentation and API improvements Feb 21, 2017
worktree_darwin.go Fix compile-time error on Windows (#251) Feb 2, 2017
worktree_linux.go Fix compile-time error on Windows (#251) Feb 2, 2017
worktree_test.go submodule init and update implementation Feb 13, 2017

README.md

go-git GoDoc Build Status codecov.io codebeat badge

A highly extensible git implementation in pure Go.

go-git aims to reach the completeness of libgit2 or jgit, nowadays covers the majority of the plumbing read operations and some of the main write operations, but lacks the main porcelain operations such as merges.

It is highly extensible, we have been following the open/close principle in its design to facilitate extensions, mainly focusing the efforts on the persistence of the objects.

... is this production ready?

The master branch represents the v4 of the library, it is currently under active development and is planned to be released in early 2017.

If you are looking for a production ready version, please take a look to the v3 which is being used in production at source{d} since August 2015 to analyze all GitHub public repositories (i.e. 16M repositories).

We recommend the use of v4 to develop new projects since it includes much new functionality and provides a more idiomatic git API

Installation

The recommended way to install go-git is:

go get -u srcd.works/go-git.v4/...

Examples

Please note that the functions CheckIfError and Info used in the examples are from the examples package just to be used in the examples.

Basic example

A basic example that mimics the standard git clone command

// Clone the given repository to the given directory
Info("git clone https://github.com/src-d/go-git")

_, err := git.PlainClone("/tmp/foo", false, &git.CloneOptions{
    URL:      "https://github.com/src-d/go-git",
    Progress: os.Stdout,
})

CheckIfError(err)

Outputs:

Counting objects: 4924, done.
Compressing objects: 100% (1333/1333), done.
Total 4924 (delta 530), reused 6 (delta 6), pack-reused 3533

In-memory example

Cloning a repository into memory and printing the history of HEAD, just like git log does

// Clones the given repository in memory, creating the remote, the local
// branches and fetching the objects, exactly as:
Info("git clone https://github.com/src-d/go-siva")

r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
    URL: "https://github.com/src-d/go-siva",
})

CheckIfError(err)

// Gets the HEAD history from HEAD, just like does:
Info("git log")

// ... retrieves the branch pointed by HEAD
ref, err := r.Head()
CheckIfError(err)

// ... retrieves the commit object
commit, err := r.Commit(ref.Hash())
CheckIfError(err)

// ... retrieves the commit history
history, err := commit.History()
CheckIfError(err)

// ... just iterates over the commits, printing it
for _, c := range history {
    fmt.Println(c)
}

Outputs:

commit ded8054fd0c3994453e9c8aacaf48d118d42991e
Author: Santiago M. Mola <santi@mola.io>
Date:   Sat Nov 12 21:18:41 2016 +0100

    index: ReadFrom/WriteTo returns IndexReadError/IndexWriteError. (#9)

commit df707095626f384ce2dc1a83b30f9a21d69b9dfc
Author: Santiago M. Mola <santi@mola.io>
Date:   Fri Nov 11 13:23:22 2016 +0100

    readwriter: fix bug when writing index. (#10)

    When using ReadWriter on an existing siva file, absolute offset for
    index entries was not being calculated correctly.
...

You can find this example and many other at the examples folder

Contribute

If you are interested on contributing to go-git, open an issue explaining which missing functionality you want to work in, and we will guide you through the implementation.

License

MIT, see LICENSE