Skip to content

Get a single branch

GET /api/v5/repos/{owner}/{repo}/branches/{branch}

Retrieves a single branch in the specified repository, returning the branch name, description, details of the commit it targets, and status flags such as whether it is merged, protected, or the default branch.

Supported access tokens

  • AtomGit user access tokens

Anonymous access allowed

This endpoint allows anonymous access.

Request parameters

Parameter Location Type Required Description
owner path string Yes Namespace address to which the repository belongs (address path of the organization or user)
repo path string Yes Repository path (path)
branch path string Yes Branch name

Response parameters

Field Type Always returned Nullable Description
name string Yes No Branch name
description string Yes No Branch description
commit object Yes No Commit information the branch points to
merged boolean Yes No Whether the branch is already merged
protected boolean Yes No Whether the branch is protected
developers_can_push boolean Yes No Whether developers can push
developers_can_merge boolean Yes No Whether developers can merge
can_push boolean Yes No Whether the current user can push
default boolean Yes No Whether this is the default branch
created_at string Yes No Creation time
creator object Yes No Creator information

commit object

Field Type Always returned Nullable Description
commit.id string Yes No Commit ID
commit.message string Yes No Commit message
commit.parent_ids string[] Yes No List of parent commit IDs
commit.authored_date string Yes No Commit authored time
commit.author_name string Yes No Commit author name
commit.author_email string Yes No Commit author email
commit.author_user_name string Yes No Commit author username
commit.committed_date string Yes No Commit time
commit.committer_name string Yes No Committer name
commit.committer_email string Yes No Committer email
commit.committer_user_name string Yes No Committer username
commit.short_id string Yes No Short commit ID
commit.created_at string Yes No Creation time
commit.title string Yes No Commit title
commit.author_avatar_url string Yes No URL of the commit author's avatar
commit.committer_avatar_url string Yes No URL of the committer's avatar

creator object

Field Type Always returned Nullable Description
creator.avatar_url string Yes No URL of the avatar
creator.id string Yes No Creator ID
creator.login string Yes No Creator login name
creator.name string Yes No Creator name

Error response

401 Unauthenticated

{
  "error": "unauthorized",
  "message": "Missing or invalid access token"
}

404 Resource does not exist

{
  "error": "not_found",
  "message": "Repository or branch does not exist"
}

The error responses above are examples only; error field names follow what the backend actually returns.

HTTP status codes

Status code Description
200 Success (OK)
401 Authentication required (Requires authentication)
403 Access forbidden (Forbidden)
404 Repository or branch does not exist (Not found)

Request example

Parameter notes

The example is consistent with the rest of this page; the placeholders mean:

Replace <owner> with the namespace address to which the repository belongs (address path of the organization or user); replace <repo> with the repository path (path); replace <branch> with the branch name.

This endpoint allows anonymous access, so the example carries no token. To call it as a user, you can also append ?access_token=<token> to the URL (<token> is your AtomGit user access token).

cURL

curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/<branch>' \
  -H 'Accept: application/json'

JavaScript

// Native fetch (Node.js 18+ / browsers)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/<branch>", {
  headers: {
    "Accept": "application/json",
  },
});

if (!response.ok) {
  throw new Error(`Request failed: ${response.status}`);
}

const data = await response.json();
console.log(data);

Python

import requests

resp = requests.get(
    "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/<branch>",
    headers={
        "Accept": "application/json",
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

Response example

Status code: 200

{
  "name": "dev",
  "description": "Development branch",
  "commit": {
    "id": "b6d44deb0ca73d7a50916d0fea02c72edd6c924e",
    "message": "Add new files to dev",
    "parent_ids": [
      "13956ffeb5e5e1ce60c2ed91d3e579fc50b1f167",
      "3e42dcb9c09b39972c65536dad71651322470f28"
    ],
    "authored_date": "2024-04-15T14:38:50.000Z",
    "author_name": "csdntest13",
    "author_email": "csdntest13@noreply.gitcode.com",
    "author_user_name": "csdntest13",
    "committed_date": "2024-04-15T14:38:50.000Z",
    "committer_name": "csdntest13",
    "committer_email": "csdntest13@noreply.gitcode.com",
    "committer_user_name": "csdntest13",
    "short_id": "b6d44deb",
    "created_at": "2024-04-15T14:38:50.000Z",
    "title": "merge refs/merge-requests/56/head into dev",
    "author_avatar_url": "https://api.atomgit.com/avatar.png",
    "committer_avatar_url": "https://api.atomgit.com/avatar.png"
  },
  "merged": false,
  "protected": false,
  "developers_can_push": false,
  "developers_can_merge": false,
  "can_push": true,
  "default": false,
  "created_at": "2024-04-15T14:38:50.000Z",
  "creator": {
    "avatar_url": "https://api.atomgit.com/avatar.png",
    "id": "494",
    "login": "csdntest13",
    "name": "csdntest13"
  }
}

Error codes

Error code Description
401 Unauthenticated or invalid credentials (missing or invalid access credentials)
403 Access forbidden
404 Repository or branch does not exist
429 Too many requests; rate limit triggered
500 Internal system error

Markdown source: View on AtomGit·Content from the open-source project gitcode-dev/atomgit-api-doc