Skip to content

grafana/nanogit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

nanogit

License Go Report Card GoDoc codecov

Overview

nanogit is a lightweight, cloud-native Git implementation designed for applications that need efficient Git operations over HTTPS without the complexity and resource overhead of traditional Git implementations.

Features

  • HTTPS-only Git operations - Works with any Git service supporting Smart HTTP Protocol v2 (GitHub, GitLab, Bitbucket, etc.), eliminating the need for SSH key management in cloud environments

  • Stateless architecture - No local .git directory dependency, making it perfect for serverless functions, containers, and microservices where persistent local state isn't available or desired

  • Memory-optimized design - Streaming packfile operations and configurable writing modes minimize memory usage, crucial for bulk operations and memory-constrained environments

  • Flexible storage architecture - Pluggable object storage and configurable writing modes allow optimization for different deployment patterns, from high-performance in-memory operations to memory-efficient disk-based processing

  • Cloud-native authentication - Built-in support for Basic Auth and API tokens, designed for automated workflows and CI/CD systems without interactive authentication

  • Essential Git operations - Focused on core functionality (read/write objects, commit operations, diffing) without the complexity of full Git implementations, reducing attack surface and resource requirements

  • High performance - Significantly faster than traditional Git implementations for common cloud operations, with up to 300x speed improvements for certain scenarios

Non-Goals

The following features are explicitly not supported:

  • git:// and Git-over-SSH protocols
  • File protocol (local Git operations)
  • Commit signing and signature verification
  • Full Git clones
  • Git hooks
  • Git configuration management
  • Direct .git directory access
  • "Dumb" servers
  • Complex permissions (all objects use mode 0644)

Why nanogit?

While go-git is a mature Git implementation, nanogit is designed for cloud-native, multitenant environments requiring minimal, stateless operations.

Feature nanogit go-git
Protocol HTTPS-only All protocols
Storage Stateless, configurable object storage + writing modes Local disk operations
Scope Essential operations only Full Git functionality
Use Case Cloud services, multitenant General purpose
Resource Usage Minimal footprint Full Git features

Choose nanogit for lightweight cloud services requiring stateless operations and minimal resources. Use go-git when you need full Git functionality, local operations, or advanced features.

This are some of the performance differences between nanogit and go-git in some of the measured scenarios:

Scenario Speed Memory Usage
CreateFile (XL repo) 262x faster 195x less
UpdateFile (XL repo) 275x faster 180x less
DeleteFile (XL repo) 269x faster 212x less
BulkCreateFiles (1000 files, medium repo) 50x faster 9x less
CompareCommits (XL repo) 111x faster 114x less
GetFlatTree (XL repo) 303x faster 137x less

For detailed performance metrics, see the latest performance report and performance analysis.

Getting Started

Prerequisites

  • Go 1.24 or later.
  • Git (for development)

Installation

go get github.com/grafana/nanogit

Usage

// Create client with authentication
client, err := nanogit.NewHTTPClient(
    "https://github.com/user/repo.git",
    options.WithBasicAuth("username", "token"),
)

// Get main branch and create staged writer
ref, err := client.GetRef(ctx, "refs/heads/main")
writer, err := client.NewStagedWriter(ctx, ref)

// Create and update files
writer.CreateBlob(ctx, "docs/new-feature.md", []byte("# New Feature"))
writer.UpdateBlob(ctx, "README.md", []byte("Updated content"))

// Commit changes with proper author/committer info
author := nanogit.Author{
    Name:  "John Doe",
    Email: "john@example.com",
    Time:  time.Now(),
}
committer := nanogit.Committer{
    Name:  "Deploy Bot",
    Email: "deploy@example.com",
    Time:  time.Now(),
}

commit, err := writer.Commit(ctx, "Add feature and update docs", author, committer)
writer.Push(ctx)

Configurable Writing Modes

nanogit provides flexible writing modes to optimize memory usage during write operations:

// Auto mode (default) - smart memory/disk switching
writer, err := client.NewStagedWriter(ctx, ref)

// Memory mode - maximum performance
writer, err := client.NewStagedWriter(ctx, ref, nanogit.WithMemoryStorage())

// Disk mode - minimal memory usage for bulk operations
writer, err := client.NewStagedWriter(ctx, ref, nanogit.WithDiskStorage())

For detailed information about writing modes, performance characteristics, and use cases, see Storage Architecture Documentation.

Storage Architecture

nanogit features a flexible two-layer storage architecture that separates concerns and allows independent optimization:

  1. Writing modes: Control temporary storage during packfile creation (memory/disk/auto)
  2. Object storage: Handle long-term caching and retrieval of Git objects (pluggable backends)

Object Storage and Caching

nanogit provides context-based object storage with pluggable backends. The default in-memory implementation is optimized for stateless operations, but you can implement custom backends for persistent caching:

// Custom storage example
ctx = storage.ToContext(ctx, myRedisStorage)
client, err := nanogit.NewHTTPClient(repo, options...)

This enables sharing Git object cache across multiple repositories, persistent caching across service restarts, and optimization for specific deployment patterns.

For detailed information about storage architecture, writing modes, and custom implementations, see Storage Architecture Documentation.

Testing

nanogit includes generated mocks for easy unit testing. The mocks are generated using counterfeiter and provide comprehensive test doubles for both the Client and StagedWriter interfaces.

For detailed testing examples and instructions, see CONTRIBUTING.md. You can also find complete working examples in mocks/example_test.go.

Contributing

We welcome contributions! Please see our Contributing Guide for details on how to submit pull requests, report issues, and set up your development environment.

Code of Conduct

This project follows the Grafana Code of Conduct. By participating, you are expected to uphold this code.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Project Status

This project is currently in active development. While it's open source, it's important to note that it was initially created as part of a hackathon. We're working to make it production-ready, but please use it with appropriate caution.

Resources

Want to learn how Git works? The following resources are useful:

Security

If you find a security vulnerability, please report it to security@grafana.com. For more information, see our Security Policy.

Support

Acknowledgments

  • The Grafana team for their support and guidance
  • The open source community for their valuable feedback and contributions

About

A minimal cloud-ready Git implementation.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6