TECHNOLOGY

GitHub Contents API: distinguish blob SHA from commit SHA

In this article
THE QUICK TAKE

A file-content SHA identifies a blob; a commit SHA identifies a repository snapshot and cannot be substituted merely because both fields are called sha.

Identify which Git object the field describes

The Git blobs reference defines a blob as the object containing a file’s contents. The Git commits reference defines a commit through a tree, parent commits and associated metadata. Both APIs return a sha, but those identifiers address different object types. An editorial integration record should label the object type beside the value. Keeping an undifferentiated variable called latest_sha invites accidental use of a branch’s commit identity where file contents are required.

Resolve the file on the intended branch

The Contents API reference accepts a ref when reading repository content and a branch when creating or updating a file. An update requires the blob SHA of the file being replaced. A proposed client should preserve repository, path and branch together with that blob identity. Reading the default branch and then updating a different branch is not a coherent observation, even when the path exists in both and their file contents sometimes coincide.

Treat representation encoding separately from object identity

The blob API exposes content with an explicit encoding, while the Contents mutation accepts Base64-encoded file contents. A blob SHA is not a hash of arbitrary reserialized API JSON or of the textual Base64 representation. An editorial fixture can use a small known byte sequence and verify decoding before constructing the update. Text newline transformations should be deliberate because they change the proposed file contents, not merely the surrounding request formatting.

Read the created commit as a separate result

The Contents update response contains content information and a commit object. Preserve both when describing what a successful mutation produced. The commit identifies the new repository history point; the returned file identity supports later inspection of that path. Creating a blob through the lower-level Git API alone does not update a branch reference. A multi-file publication using trees and commits is consequently a different workflow from one Contents API file operation.

Make conflict handling specific to the file workflow

The Contents reference warns that concurrent create/update and delete operations can conflict and should be performed serially. A proposed client must resolve a conflict against the intended file and branch rather than replacing every SHA with an arbitrary newest commit. Contract fixtures help preserve object-type checks, while release manifests explain why successfully changing one repository file does not establish a coherent model-artifact release. This guide describes the API contract and performs no repository mutation.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles