The Git Objects API
A comprehensive guide to working with Git objects (blobs, commits, trees, tags, and refs) in Freestyle
Git Objects API
The Git Objects API allows you to access and explore Git objects directly from your repositories. This API is useful for building tools that need to understand Git repository structure, inspect files, visualize commit history, and more.
Overview
Git stores all data as objects of four fundamental types:
- Blobs - Raw file content
- Trees - Directory listings mapping names to blobs or other trees
- Commits - Snapshots of the repository at a specific point in time
- Tags - References to specific commits with additional metadata
The Git Objects API in Freestyle provides access to all these object types through a consistent REST API.
Usage
Blobs
Blobs represent the content of files in Git. When you retrieve a blob, you get the raw file content (always base64 encoded for binary safety).
Get a Blob
Response structure:
Commits
Commits represent snapshots of your repository at specific points in time.
Get a Commit
Response structure:
Trees
Trees represent directories in Git. A tree object contains a list of entries, each with a name, type (blob or tree), and hash.
Get a Tree
Response structure:
Tags
Tags are references to specific objects (usually commits) with additional metadata like tagger information and a message.
Get a Tag
Response structure:
Common Use Cases
Processing Files from a Git Trigger
When a Git trigger is invoked by a push to your repository, Freestyle sends a payload containing information about the event, including the commit hash. You can use this to inspect files that were changed in the commit:
Building a File Browser
You can build a recursive file browser:
Viewing File Contents from a Specific Commit
Best Practices
- Cache results when possible - Git objects are immutable, so you can safely cache them
- Handle binary data correctly - Remember that blob content is base64 encoded
Conclusion
The Git Objects API provides low-level access to Git repository data, enabling you to build powerful tools for Git repository management, visualization, and integration with other systems.
For detailed API reference documentation, see the API Reference section.
Refs API coming soon.