config: support a configurable, and turn-off-able, pack.window

One use of go-git is to transfer git data from a non-standard git repo
(not stored in a file system, for example) to a "remote" backed by a
standard, local .git repo.

In this scenario, delta compression is not needed to reduce transfer
time over the "network", because there is no network. The underlying
storage layer has already taken care of the data tranfer, and sending
the objects to local .git storage doesn't require compression. So this
PR gives the user the option to turn off compression when it isn't

Of course, this results in a larger, uncompressed local .git repo, but
the user can then run git gc or git repack on that repo if they care
about the storage costs.

Turning the pack window to 0 on reduces total push time of a 36K repo
by 50 seconds (out of a pre-PR total of 3m26s).
10 files changed
tree: 582a03b677b2a4c34c46c83f6511ad141c7b3ccb
  1. .gitignore
  2. .travis.yml
  3. .travis/
  6. Makefile
  8. _examples/
  9. appveyor.yml
  10. blame.go
  11. blame_test.go
  12. cli/
  13. common.go
  14. common_test.go
  15. config/
  16. doc.go
  17. example_test.go
  18. internal/
  19. options.go
  20. options_test.go
  21. plumbing/
  22. references.go
  23. references_test.go
  24. remote.go
  25. remote_test.go
  26. repository.go
  27. repository_test.go
  28. repository_unix_test.go
  29. repository_windows_test.go
  30. status.go
  31. storage/
  32. submodule.go
  33. submodule_test.go
  34. utils/
  35. worktree.go
  36. worktree_commit.go
  37. worktree_commit_test.go
  38. worktree_darwin.go
  39. worktree_linux.go
  40. worktree_status.go
  41. worktree_test.go
  42. worktree_windows.go

go-git GoDoc Build Status Build status 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


The recommended way to install go-git is:

go get -u


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")

_, err := git.PlainClone("/tmp/foo", false, &git.CloneOptions{
    URL:      "",
    Progress: os.Stdout,



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")

r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
    URL: "",


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

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

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

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

// ... just iterates over the commits, printing it
for _, c := range history {


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

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

commit df707095626f384ce2dc1a83b30f9a21d69b9dfc
Author: Santiago M. Mola <>
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

Comparison With Git

In the compatibility documentation you can find a comparison table of git with go-git.


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.