Categorygithub.com/smallcase/go-git/v5
modulepackage
5.4.3
Repository: https://github.com/smallcase/go-git.git
Documentation: pkg.go.dev

# README

go-git logo GoDoc Build Status Go Report Card

go-git is a highly extensible git implementation library written in pure Go.

It can be used to manipulate git repositories at low level (plumbing) or high level (porcelain), through an idiomatic Go API. It also supports several types of storage, such as in-memory filesystems, or custom implementations, thanks to the Storer interface.

It's being actively developed since 2015 and is being used extensively by Keybase, Gitea or Pulumi, and by many other libraries and tools.

Project Status

After the legal issues with the src-d organization, the lack of update for four months and the requirement to make a hard fork, the project is now back to normality.

The project is currently actively maintained by individual contributors, including several of the original authors, but also backed by a new company, gitsight, where go-git is a critical component used at scale.

Comparison with git

go-git aims to be fully compatible with git, all the porcelain operations are implemented to work exactly as git does.

git is a humongous project with years of development by thousands of contributors, making it challenging for go-git to implement all the features. You can find a comparison of go-git vs git in the compatibility documentation.

Installation

The recommended way to install go-git is:

import "github.com/go-git/go-git/v5" // with go modules enabled (GO111MODULE=on or outside GOPATH)
import "github.com/go-git/go-git" // with go modules disabled

Examples

Please note that the CheckIfError and Info functions 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/go-git/go-git")

_, err := git.PlainClone("/tmp/foo", false, &git.CloneOptions{
    URL:      "https://github.com/go-git/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/go-git/go-billy")

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

CheckIfError(err)

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

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


// ... retrieves the commit history
cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
CheckIfError(err)

// ... just iterates over the commits, printing it
err = cIter.ForEach(func(c *object.Commit) error {
	fmt.Println(c)
	return nil
})
CheckIfError(err)

Outputs:

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

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

commit df707095626f384ce2dc1a83b30f9a21d69b9dfc
Author: Santiago M. Mola <[email protected]>
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 others in the examples folder.

Contribute

Contributions are more than welcome, if you are interested please take a look to our Contributing Guidelines.

License

Apache License Version 2.0, see LICENSE

# Packages

No description provided by the author
Package config contains the abstraction of multiple config files.
package plumbing implement the core interfaces and structs used by go-git.
No description provided by the author
No description provided by the author

# Functions

Blame returns a BlameResult with the information about the last author of each line from file `path` at commit `c`.
Clone a repository into the given Storer and worktree Filesystem with the given options, if worktree is nil a bare repository is created.
CloneContext a repository into the given Storer and worktree Filesystem with the given options, if worktree is nil a bare repository is created.
Init creates an empty git repository, based on the given Storer and worktree.
NewRemote creates a new Remote.
Open opens a git repository using the given Storer and worktree filesystem, if the given storer is complete empty ErrRepositoryNotExists is returned.
PlainClone a repository into the path with the given options, isBare defines if the new repository will be bare or normal.
PlainCloneContext a repository into the path with the given options, isBare defines if the new repository will be bare or normal.
PlainInit create an empty git repository at the given path.
PlainOpen opens a git repository from the given path.
PlainOpenWithOptions opens a git repository from the given path with specific options.

# Constants

No description provided by the author
AllTags fetch all tags from the remote (i.e., fetch remote tags refs/tags/* into local tags with the same name).
No description provided by the author
DefaultRemoteName name of the default Remote, just like git command.
DefaultSubmoduleRecursionDepth allow recursion in a submodule operation.
No description provided by the author
GitDirName this is a special folder where all the git stuff is.
HardReset resets the index and working tree.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
MergeReset resets the index and updates the files in the working tree that are different between Commit and HEAD, but keeps those which are different between the index and working tree (i.e.
MixedReset resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated.
No description provided by the author
NoRecurseSubmodules disables the recursion for a submodule operation.
NoTags fetch no tags from the remote at all.
No description provided by the author
SoftReset does not touch the index file or the working tree at all (but resets the head to <commit>, just like all modes do).
TagFollowing any tag that points into the histories being fetched is also fetched.
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
ErrBranchExists an error stating the specified branch already exists.
No description provided by the author
ErrBranchNotFound an error stating the specified branch does not exist.
No description provided by the author
No description provided by the author
ErrDestinationExists in an Move operation means that the target exists on the worktree.
No description provided by the author
ErrFetching is returned when the packfile could not be downloaded.
No description provided by the author
No description provided by the author
ErrGlobNoMatches in an AddGlob if the glob pattern does not match any files in the worktree.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ErrTagExists an error stating the specified tag already exists.
ErrTagNotFound an error stating the specified tag does not exist.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

AddOptions describes how an `add` operation should be performed.
BlameResult represents the result of a Blame operation.
CheckoutOptions describes how a checkout operation should be performed.
CleanOptions describes how a clean should be performed.
CloneOptions describes how a clone should be performed.
CommitOptions describes how a commit operation should be performed.
CreateTagOptions describes how a tag object should be created.
FetchOptions describes how a fetch should be performed.
FileStatus contains the status of a file in the worktree.
ForceWithLease sets fields on the lease If neither RefName nor Hash are set, ForceWithLease protects all refs in the refspec by ensuring the ref of the remote in the local repsitory matches the one in the ref advertisement.
GrepOptions describes how a grep should be performed.
GrepResult is structure of a grep result.
Line values represent the contents and author of a line in BlamedResult values.
ListOptions describes how a remote list should be performed.
LogOptions describes how a log action should be performed.
No description provided by the author
PlainOpenOptions describes how opening a plain repository should be performed.
No description provided by the author
PullOptions describes how a pull should be performed.
PushOptions describes how a push should be performed.
Remote represents a connection to a remote repository.
No description provided by the author
Repository represents a git repository.
ResetOptions describes how a reset operation should be performed.
Submodule a submodule allows you to keep another Git repository in a subdirectory of your repository.
SubmoduleStatus contains the status for a submodule in the worktree.
SubmoduleUpdateOptions describes how a submodule update should be performed.
Worktree represents a git worktree.

# Type aliases

No description provided by the author
No description provided by the author
ResetMode defines the mode of a reset operation.
Status represents the current status of a Worktree.
StatusCode status code of a file in the Worktree.
SubmoduleRescursivity defines how depth will affect any submodule recursive operation.
Submodules list of several submodules from the same repository.
SubmodulesStatus contains the status for all submodiles in the worktree.
No description provided by the author