Skip to main content
OperationsService provides an interface for performing mutating git operations on a repository on behalf of a user. The user’s operation is treated as untrusted. Any reference update is checked against GitLab’s /allowed endpoint.

UserCreateBranch

Creates a new branch in the repository.

Request

repository
Repository
required
The repository where the branch will be created
branch_name
bytes
required
Name of the branch to create
user
User
required
User performing the operation
start_point
bytes
required
Commit SHA or reference to create the branch from

Response

branch
Branch
The created branch object
pre_receive_error
string
Error returned by the pre-receive hook. Empty string if no error occurred

UserUpdateBranch

Updates an existing branch to point to a new commit.

Request

repository
Repository
required
The repository containing the branch
branch_name
bytes
required
Name of the branch to update
user
User
required
User performing the operation
newrev
bytes
required
New commit SHA to update the branch to
oldrev
bytes
required
Current commit SHA of the branch for safety check

Response

pre_receive_error
string
Error returned by the pre-receive hook. Empty string if no error occurred

UserDeleteBranch

Deletes a branch from the repository.

Request

repository
Repository
required
The repository containing the branch
branch_name
bytes
required
Name of the branch to delete
user
User
required
User performing the operation

Response

pre_receive_error
string
Error returned by the pre-receive hook. Empty string if no error occurred

UserCreateTag

Creates a new tag in the repository. Creates either a lightweight or annotated tag based on whether a message is provided.

Request

repository
Repository
required
The repository in which the tag shall be created
tag_name
bytes
required
Name of the tag to create
user
User
required
User as which the tag shall be created
target_revision
bytes
required
Revision which the tag should point to
message
bytes
Message for the tag. If empty, a lightweight tag is created. Otherwise, an annotated tag is created
timestamp
Timestamp
Optional timestamp to use for the created tag. Only used for annotated tags. Current time is used if not set

Response

tag
Tag
The newly created tag
exists
bool
Denotes whether the tag already existed
pre_receive_error
string
Error message if updating the tag failed because of a pre-receive error

UserDeleteTag

Deletes a tag from the repository.

Request

repository
Repository
required
The repository containing the tag
tag_name
bytes
required
Name of the tag to delete
user
User
required
User performing the operation

Response

pre_receive_error
string
Error returned by the pre-receive hook. Empty string if no error occurred

UserMergeToRef

Creates a merge commit and updates target_ref to point to that new commit. The first parent of the merge commit (the main line) is taken from first_parent_ref. The second parent is specified by its commit ID in source_sha. If target_ref already exists it will be overwritten.

Request

repository
Repository
required
The repository in which the merge shall be computed
user
User
required
User as which the merge commit shall be created
source_sha
string
required
Object ID of the second parent of the computed merge
target_ref
bytes
required
Fully qualified reference which should be updated with the computed merge commit
message
bytes
required
Message to use for the merge commit
first_parent_ref
bytes
required
Name of the reference to use as the first parent of the computed merge
allow_conflicts
bool
Allow conflicts to occur. Conflict markers will be part of the merge commit
timestamp
Timestamp
Optional timestamp to use for the merge commit. Current time is used if not set

Response

commit_id
string
Object ID of the computed merge commit

UserMergeBranch

Tries to merge the given commit into the target branch. The merge commit is created with the given user as author/committer and the given message. This RPC requires confirmation to make any user-visible changes to the repository. Streaming RPC: This is a bidirectional streaming RPC. First request contains merge details, server responds with the merge commit ID. Second request with apply = true confirms the merge.

Request

repository
Repository
required
The repository to compute the merge for (first message only)
user
User
required
User to compute the merge as. Used as author and committer (first message only)
commit_id
string
required
Object ID of the commit to merge into the target branch (first message only)
branch
bytes
required
Branch into which the commit shall be merged (first message only)
message
bytes
required
Message to use for the merge commit (first message only)
timestamp
Timestamp
Optional timestamp for the merge commit. Current time is used if not set (first message only)
apply
bool
Must be set to true in the second message to confirm and apply the merge

Response

commit_id
string
Merge commit ID that the branch will be updated to (first response)
branch_update
OperationBranchUpdate
Set if the merge has been applied to the branch (second response)

UserFFBranch

Tries to perform a fast-forward merge of the given branch to the given commit. If the merge is not a fast-forward merge, the request will fail. Returns an empty response if updating the reference fails due to a race condition.

Request

repository
Repository
required
The repository for which to perform the fast-forward merge
user
User
required
User to perform the fast-forward merge as. Used for authorization checks
commit_id
string
required
Commit ID to update the branch to
branch
bytes
required
Name of the branch to update (branch name only, not fully qualified reference)

Response

branch_update
OperationBranchUpdate
Details about the updated branch
pre_receive_error
string
Error returned by the pre-receive hook. Empty string if no error occurred

UserCherryPick

Tries to perform a cherry-pick of a given commit onto a branch.

Request

repository
Repository
required
The repository into which the cherry-pick shall be performed
user
User
required
User to perform the cherry-pick as. Used for authorization and as the committer
commit
GitCommit
required
Commit to cherry-pick onto the given branch
branch_name
bytes
required
Name of the branch onto which the cherry-pick shall be executed
message
bytes
required
Message to use for the cherry-picked commit
start_branch_name
bytes
Used if branch_name doesn’t exist. Branch will be created from this branch
start_repository
Repository
Repository containing start_branch_name if branch_name doesn’t exist
dry_run
bool
Compute the cherry-pick but don’t update the target branch
timestamp
Timestamp
Optional timestamp for the cherry-picked commit’s committer date. Current time is used if not set

Response

branch_update
OperationBranchUpdate
Details about the updated branch
create_tree_error
string
Error message if creation of the tree failed
commit_error
string
Error message if updating the reference failed
pre_receive_error
string
Error message if the pre-receive hook failed
create_tree_error_code
CreateTreeError
Error code if creation of the tree failed. Values: NONE (0), EMPTY (1), CONFLICT (2)

UserCommitFiles

Builds a commit from a stream of actions and updates the target branch to point to it. The first message must contain a header with commit details, followed by a variable number of actions. Streaming RPC: Send header first, then stream actions. Each action has a header followed by content if needed.

Request

header
UserCommitFilesRequestHeader
required
Must be sent as the first message in the stream
header.repository
Repository
required
Target repository where to apply the commit
header.user
User
required
User performing the call
header.branch_name
bytes
required
Name of the branch to point to the new commit
header.commit_message
bytes
required
Message to use in the commit
header.commit_author_name
bytes
Commit author’s name. User’s name is used if not provided
header.commit_author_email
bytes
Commit author’s email. User’s email is used if not provided
header.start_branch_name
bytes
Branch whose commit to use as parent. Takes priority over branch_name
header.start_repository
Repository
Repository containing the parent commit. Uses repository if not specified
header.force
bool
Force update the target branch to point to the new commit
header.start_sha
string
SHA of commit to use as parent. Takes priority over start_branch_name and branch_name
header.timestamp
Timestamp
Optional timestamp to use for the commit. Current time is used if not set
action
UserCommitFilesAction
Action to build a commit. Multiple actions can be sent per stream
action.header
UserCommitFilesActionHeader
Action details. Must be sent before content
action.header.action
ActionType
required
Type of action: CREATE (0), CREATE_DIR (1), UPDATE (2), MOVE (3), DELETE (4), CHMOD (5)
action.header.file_path
bytes
required
Path of the file or directory being modified
action.header.previous_path
bytes
Used in MOVE action to specify the path of the file to move
action.header.base64_content
bool
Indicates the content is base64 encoded (RFC 4648). Only for CREATE and UPDATE actions
action.header.execute_filemode
bool
Create file with execute permissions. Only for CREATE and CHMOD actions
action.header.infer_content
bool
For MOVE actions that only change path, not content. Set to true instead of populating content
action.content
bytes
File content streamed in one or more messages. Only for CREATE and UPDATE actions

Response

branch_update
OperationBranchUpdate
Details of the commit and branch update
index_error
string
Error message for invalid actions (e.g., creating a file that already exists)
pre_receive_error
string
Error message if the pre-receive hook failed

UserRebaseConfirmable

Rebases the given remote branch onto a target branch. The remote branch may be part of another repository. This RPC requires confirmation to make any user-visible changes to the repository. Streaming RPC: First request contains rebase details, server responds with the rebase commit ID. Second request with apply = true confirms the rebase.

Request

header
Header
required
Must be sent as the first message (first message only)
header.repository
Repository
required
Repository in which the rebase will be computed and applied
header.user
User
required
User to compute the rebase as. Used as committer of rebased commits
header.branch
bytes
required
Branch onto which the rebase shall happen
header.branch_sha
string
required
Expected object ID that branch currently points to. Safety guard against races
header.remote_repository
Repository
required
Repository containing the branch to rebase onto the local branch
header.remote_branch
bytes
required
Branch name to rebase onto the local branch
header.git_push_options
string[]
Options to pass to git hooks when updating the local branch
header.timestamp
Timestamp
Optional timestamp for rebased commits as committer date. Current time is used if not set
apply
bool
Must be set to true in the second message to confirm the rebase

Response

rebase_sha
string
Rebase commit ID that the branch will be updated to (first response)
rebase_applied
bool
Confirms that the rebase has been applied to the branch (second response)
pre_receive_error
string
Error message if the rebase failed due to hooks
git_error
string
Error message if git operations failed

UserRevert

Tries to perform a revert of a given commit onto a branch.

Request

repository
Repository
required
The repository in which the revert shall be applied
user
User
required
User to perform the revert as. Used for authorization and as author/committer
commit
GitCommit
required
Commit to revert
branch_name
bytes
required
Name of the branch onto which the reverted commit shall be committed
message
bytes
required
Message to use for the revert commit
start_branch_name
bytes
Used if branch_name doesn’t exist. Branch will be created from this branch
start_repository
Repository
Repository containing start_branch_name if branch_name doesn’t exist
dry_run
bool
Compute the revert but don’t update the target branch
timestamp
Timestamp
Optional timestamp for the revert commit’s committer date. Current time is used if not set

Response

branch_update
OperationBranchUpdate
Details about the updated branch
create_tree_error
string
Error message if creation of the tree failed
commit_error
string
Error message if updating the reference failed
pre_receive_error
string
Error message if the pre-receive hook failed
create_tree_error_code
CreateTreeError
Error code if creation of the tree failed. Values: NONE (0), EMPTY (1), CONFLICT (2)

UserSquash

Squashes a range of commits into a single commit. Returns the object ID of the newly created squash commit on success.

Request

repository
Repository
required
The repository into which the squashed commit shall be written
user
User
required
User for authorization checks
start_sha
string
required
Object ID of the start commit of the range to squash. Must be an ancestor of end_sha
end_sha
string
required
Object ID of the end commit of the range to squash
author
User
required
User to be used as the author of the squashed commit
commit_message
bytes
required
Message to use for the squashed commit
timestamp
Timestamp
Optional timestamp for the squashed commit as committer date. Current time is used if not set

Response

squash_sha
string
Object ID of the squashed commit

UserApplyPatch

Applies patches to a given branch. Streaming RPC: First message contains header with configuration, subsequent messages contain patch data.

Request

header
Header
required
Must be sent as the first message
header.repository
Repository
required
Repository to which patches shall be applied
header.user
User
required
User for authentication
header.target_branch
bytes
required
Branch onto which the patches shall be applied
header.timestamp
Timestamp
Optional timestamp for the commits as committer date. Current time is used if not set
patches
bytes
Patch data streamed in subsequent messages

Response

branch_update
OperationBranchUpdate
Information about the updated branch

UserUpdateSubmodule

Updates a submodule to point to a new commit.

Request

repository
Repository
required
The repository in which the submodule shall be updated
user
User
required
User for authorization and as author/committer of the resulting commit
commit_sha
string
required
Object ID the submodule shall be updated to
branch
bytes
required
Branch to update (unqualified name, without refs/heads/ prefix)
submodule
bytes
required
Path to the submodule to update
commit_message
bytes
required
Message for the update commit
timestamp
Timestamp
Optional timestamp for the update commit as committer date. Current time is used if not set

Response

branch_update
OperationBranchUpdate
Information about the updated branch
pre_receive_error
string
Error message if the pre-receive hook rejects the update
commit_error
string
Error message if committing the update fails

Build docs developers (and LLMs) love