Skip to content
DELETE/repos/{owner}/{name}/branches/{branch}

Needs the Write role or higher, and the repository’s rules for deleting the branch hold; the default branch is never deleted. Give head, the commit you saw it at, to leave it alone if someone has pushed since. Returns the branch as it was: its commits stay in the repository, so create_branch with that commit as from restores it. Open pull requests from it can no longer be updated or merged until it is back. Give a branch with slashes URL-encoded in the path, e.g. feature%2Flogin.

The branch as it was. Its commits stay in the repository: POST /repos/{owner}/{name}/branches with this hash as from restores it. Add ?head=<sha> to leave it alone (409) if it has moved from the commit you saw. Refused with 403 for the default branch, without the Write role, or when the repository’s rules refuse it, and 404 when there is no such branch. Send a branch name with slashes URL-encoded, as one path segment. See Branches.

  • Authentication: Required. Send an access token as Authorization: Bearer.
  • MCP tool: repository with action delete_branch, and the same inputs
  • Scope: An access token needs repo:write.
Name Type Required Description
owner string Yes The workspace that owns the repository.
name string Yes The repository’s name.
branch string Yes The branch to delete, e.g. “feature/login”. URL-encode slashes in the path.

Send a JSON object. Names are snake_case, as in responses; the camelCase spelling is accepted too.

Name Type Required Description
head string No The commit you saw it at. If it has moved since, it is left alone (409).
curl -X DELETE https://api.g1t.sh/repos/flagon-io/hello/branches/feature%2Flogin \
-H "Authorization: Bearer $G1T_TOKEN"

A successful request answers 200 with:

{
"name": "feature/login",
"hash": "9f2c4e1b7a3d5c6e8f0a1b2c3d4e5f6a7b8c9d0e"
}

A failed request answers with one of these statuses and a body like {"error": {"code": "not_found", "message": "Repository not found."}}. See errors.

Status Code When
401 unauthenticated A token is required, or the one sent is not valid.
403 forbidden The token is valid but not allowed to do this, such as a member-only change or an agent token outside its repository.
404 not_found It does not exist, or you cannot see it.
409 conflict The request conflicts with the current state.
422 invalid The input is not valid. message says which field and why.