Skip to main content
The RepositoryService provides RPCs for managing Git repositories at the repository level. This includes operations for creating, optimizing, backing up, and inspecting repositories.

RepositoryExists

Checks if a repository exists at the specified path.

Request

repository
Repository
required
The repository to check for existence

Response

exists
bool
True if the repository exists, false otherwise

Example

{
  "repository": {
    "storage_name": "default",
    "relative_path": "@hashed/ab/cd/abcd1234.git"
  }
}

RepositorySize

Returns the size of the repository in kilobytes.

Request

repository
Repository
required
The repository to measure

Response

size
int64
Repository size in kilobytes

CreateRepository

Creates a new empty repository.

Request

repository
Repository
required
The repository to create
default_branch
bytes
Branch name to set as the default branch. This will be treated as the branch name and not a fully qualified reference.

Example

{
  "repository": {
    "storage_name": "default",
    "relative_path": "@hashed/ab/cd/abcd1234.git"
  },
  "default_branch": "main"
}

OptimizeRepository

Performs all maintenance tasks to keep the repository in an efficient state. This includes cleaning up stale data, repacking objects, updating auxiliary caches like commit-graphs, and packing references.

Request

repository
Repository
required
The repository to optimize

Response

Empty response on success.

Example

{
  "repository": {
    "storage_name": "default",
    "relative_path": "@hashed/ab/cd/abcd1234.git"
  }
}

PruneUnreachableObjects

Prunes all objects which aren’t reachable from the repository’s current set of references. Objects must not have been accessed or modified in the last 30 minutes.
You must call OptimizeRepository first to explode unreachable objects into loose objects, wait 30 minutes, then call PruneUnreachableObjects.

Request

repository
Repository
required
The repository to prune

Response

Empty response on success.

FetchRemote

Fetches references from a remote repository into the local repository.

Request

repository
Repository
required
Target repository to fetch into
remote_params
Remote
required
Remote repository configuration
force
bool
Force-update references if they have diverged
no_tags
bool
Skip fetching tags
timeout
int32
Timeout in seconds for the fetch operation
no_prune
bool
Don’t prune remote references that no longer exist
check_tags_changed
bool
Check whether any tags were modified

Response

tags_changed
bool
True if tags were changed or cannot be determined. Only set if check_tags_changed was true.

FetchSourceBranch

Fetches a branch from a second (potentially remote) repository into the given repository.

Request

repository
Repository
required
Target repository to fetch into
source_repository
Repository
required
Source repository to fetch from
source_branch
bytes
required
Name of the branch in the source repository
target_ref
bytes
required
Name of the reference to create in the target repository

Response

result
bool
True if the source branch was successfully fetched, false if resolving or fetching failed

GetArchive

Generates an archive (tar, tar.gz, tar.bz2, or zip) from the repository at a specific commit.

Request

repository
Repository
required
The repository to archive
commit_id
string
required
The commit to create the archive from
prefix
string
Prefix to add to all paths in the archive
format
Format
required
Archive format: ZIP, TAR, TAR_GZ, or TAR_BZ2
path
bytes
Limit archive to a specific subdirectory
exclude
bytes[]
Patterns to exclude from the archive
elide_path
bool
If true and path refers to a subdirectory, elide that subdirectory from archive entries
include_lfs_blobs
bool
Include LFS blob content in the archive

Response (Stream)

data
bytes
Chunk of archive data

CreateBundle

Creates a bundle from all refs in the repository.

Request

repository
Repository
required
The repository to bundle

Response (Stream)

data
bytes
Chunk of bundle data

CreateBundleFromRefList

Creates a bundle from a stream of ref patterns. Returns FailedPrecondition error if the bundle would be empty.

Request (Stream)

repository
Repository
required
The repository to bundle (first message only)
patterns
bytes[]
Patterns in the format accepted by git-rev-list(1). Patterns which don’t match any reference will be silently ignored.

Response (Stream)

data
bytes
Chunk of bundle data

FetchBundle

Fetches references from a bundle into the local repository. Refs will be mirrored with the refspec “+refs/:refs/” and refs that do not exist in the bundle will be removed.

Request (Stream)

repository
Repository
required
Repository to fetch into (first message only)
data
bytes
Bundle file stream data
update_head
bool
Update HEAD if there is a HEAD reference listed in the bundle

Response

Empty response on success.

CreateRepositoryFromBundle

Creates a new repository from a bundle file.

Request (Stream)

repository
Repository
required
The repository to create (first message only)
data
bytes
Bundle file stream data

Response

Empty response on success.

CreateFork

Creates a fork of a repository.

Request

repository
Repository
required
The repository to create as a fork
source_repository
Repository
required
The repository to fork from

Response

Empty response on success.

CreateRepositoryFromURL

Creates a repository by cloning from a URL.

Request

repository
Repository
required
The repository to create
url
string
required
URL to clone from
http_host
string
Hostname of the remote repository. Use this when the URL hostname has been resolved to an IP address to prevent DNS rebinding.
http_authorization_header
string
HTTP authorization header for authentication
mirror
bool
If true, creates a complete mirror clone which maps all remote references. If false (default), creates a bare clone with only branches and tags.

Response

Empty response on success.

GetConfig

Reads the target repository’s gitconfig and streams its contents. Returns NotFound error if no gitconfig was found.

Request

repository
Repository
required
The repository to read config from

Response (Stream)

data
bytes
Chunk of gitconfig contents

ApplyGitattributes

Applies gitattributes from a specific revision to the repository.

Request

repository
Repository
required
The repository to apply gitattributes to
revision
bytes
required
The revision containing the .gitattributes file

Response

Empty response on success.

Fsck

Runs git fsck to check the repository for corruption.

Request

repository
Repository
required
The repository to check

Response

error
bytes
Error message if fsck found issues, empty if repository is healthy

WriteRef

Writes a reference to point to a specific revision.

Request

repository
Repository
required
The repository to write the ref in
ref
bytes
required
The reference name to write
revision
bytes
required
The revision the ref should point to
old_revision
bytes
Expected old revision for atomic updates
force
bool
Force update even if it’s not a fast-forward

Response

Empty response on success.

FindMergeBase

Finds the merge base commit between multiple revisions.

Request

repository
Repository
required
The repository to search in
revisions
bytes[]
required
The revisions to find the merge base for (supports more than 2 revisions)

Response

base
string
The merge base commit ID, empty if no merge base found

HasLocalBranches

Checks if the repository has any local branches.

Request

repository
Repository
required
The repository to check

Response

value
bool
True if the repository has local branches

FindLicense

Detects the license of the repository.

Request

repository
Repository
required
The repository to analyze

Response

license_short_name
string
Short name of the detected license (e.g., “MIT”, “Apache-2.0”)

GetInfoAttributes

Retrieves the contents of the repository’s info/attributes file.

Request

repository
Repository
required
The repository to read from

Response (Stream)

attributes
bytes
Chunk of attributes file content

CalculateChecksum

Calculates a checksum of the repository’s content.

Request

repository
Repository
required
The repository to checksum

Response

checksum
string
The calculated checksum

GetSnapshot

Creates a snapshot of the repository as a tar archive.

Request

repository
Repository
required
The repository to snapshot

Response (Stream)

data
bytes
Chunk of snapshot data

CreateRepositoryFromSnapshot

Creates a repository from a remote snapshot URL.

Request

repository
Repository
required
The repository to create
http_url
string
required
URL of the snapshot
http_auth
string
Authentication credentials
http_host
string
Hostname of the remote snapshot. Use this when the URL hostname has been resolved to an IP address to prevent DNS rebinding.

Response

Empty response on success.

GetRawChanges

Returns the raw changes between two revisions.

Request

repository
Repository
required
The repository to analyze
from_revision
string
required
Starting revision
to_revision
string
required
Ending revision

Response (Stream)

raw_changes
RawChange[]
Array of raw changes between revisions
raw_changes[].blob_id
string
Object ID of the blob
raw_changes[].size
int64
Size of the blob
raw_changes[].operation
Operation
Type of operation: ADDED, COPIED, DELETED, MODIFIED, RENAMED, TYPE_CHANGED
raw_changes[].old_mode
int32
Old file mode
raw_changes[].new_mode
int32
New file mode
raw_changes[].new_path_bytes
bytes
New path of the file
raw_changes[].old_path_bytes
bytes
Old path of the file

SearchFilesByName

Searches for files by name pattern.

Request

repository
Repository
required
The repository to search in
query
string
required
Search query pattern
ref
bytes
required
Reference to search at
filter
string
Regular expression to filter results (max 1000 bytes)

Response (Stream)

files
bytes[]
Array of matching file paths

SearchFilesByContent

Searches for files by content pattern.

Request

repository
Repository
required
The repository to search in
query
string
required
Search query pattern
ref
bytes
required
Reference to search at
chunked_response
bool
Enable chunked response mode

Response (Stream)

matches
bytes[]
Array of matching content
match_data
bytes
Raw match data in chunked mode
end_of_match
bool
Indicates end of a match in chunked mode

RestoreCustomHooks

Restores custom hooks to the repository from a tar archive.

Request (Stream)

repository
Repository
required
The repository to restore hooks to (first message only)
data
bytes
Tar archive data containing hooks

Response

Empty response on success.

BackupCustomHooks

Backs up custom hooks from the repository as a tar archive.

Request

repository
Repository
required
The repository to backup hooks from

Response (Stream)

data
bytes
Chunk of tar archive data

GetObjectDirectorySize

Returns the size of the repository’s object directory in kilobytes.

Request

repository
Repository
required
The repository to measure

Response

size
int64
Object directory size in kilobytes

RemoveRepository

Removes a repository by moving it to a temporary location before deletion.

Request

repository
Repository
required
The repository to remove

Response

Empty response on success.

RenameRepository

Renames a repository to a new relative path.

Request

repository
Repository
required
The repository to rename
relative_path
string
required
New relative path for the repository

Response

Empty response on success.

ReplicateRepository

Replicates a repository from a source.

Request

repository
Repository
required
The target repository
source
Repository
required
The source repository to replicate from

Response

Empty response on success.

SetFullPath

Writes the “gitlab.fullpath” configuration into the repository’s gitconfig for debugging purposes.

Request

repository
Repository
required
The repository to configure
path
string
required
The full path to write into the gitlab.fullpath config key

Response

Empty response on success.

Build docs developers (and LLMs) love