> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blackbox.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get GitHub Branches

> Retrieve all branches from a specific GitHub repository.

This endpoint returns a list of all branches in a specified GitHub repository, including branch names, protection status, and default branch information.

## Authentication

To use this API, you need a BLACKBOX API Key. Follow these steps to get your API key:

1. **Click on your Profile Image** in the top right corner at [cloud.blackbox.ai](https://cloud.blackbox.ai)
2. **Click on "BLACKBOX API Token"** from the dropdown menu
3. **Copy the existing token** or **click "Generate"** if you don't have one yet

Your API key will be in the format: `bb_xxxxxxxxxxxxxxxxxxxxxx`

## Headers

<ParamField header="Authorization" type="string" required>
  API Key of the form `Bearer <api_key>`.

  Example: `Bearer bb_b41b647ffbfed27f61656049d3eaeef3d903cc503345d9eb80080d98bc0`
</ParamField>

## Query Parameters

<ParamField query="owner" type="string" required>
  The GitHub username or organization name that owns the repository.

  Example: `example-user` or `example-org`
</ParamField>

<ParamField query="repo" type="string" required>
  The repository name from which to retrieve branches.

  Example: `example-repo`
</ParamField>

## Response

The endpoint returns an array of branch objects.

<ResponseField name="name" type="string">
  The name of the branch.
</ResponseField>

<ResponseField name="protected" type="boolean">
  Whether the branch is protected from force pushes and deletion.
</ResponseField>

<ResponseField name="isDefault" type="boolean">
  Whether this is the default branch of the repository (typically `main` or `master`).
</ResponseField>

<RequestExample>
  ```bash cURL theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  curl --location 'https://cloud.blackbox.ai/api/github/branches?owner=example-user&repo=example-repo' \
  --header 'Authorization: Bearer YOUR_API_KEY'
  ```

  ```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  const API_KEY = "YOUR_API_KEY";
  const owner = "example-user";
  const repo = "example-repo";
  const API_URL = `https://cloud.blackbox.ai/api/github/branches?owner=${owner}&repo=${repo}`;

  const response = await fetch(API_URL, {
      method: "GET",
      headers: {
          Authorization: `Bearer ${API_KEY}`,
      },
  });

  const branches = await response.json();
  console.log(branches);
  ```

  ```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  import requests

  API_KEY = "YOUR_API_KEY"
  owner = "example-user"
  repo = "example-repo"
  API_URL = f"https://cloud.blackbox.ai/api/github/branches?owner={owner}&repo={repo}"

  headers = {
      "Authorization": f"Bearer {API_KEY}"
  }

  response = requests.get(API_URL, headers=headers)
  branches = response.json()
  print(branches)
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  [
      {
          "name": "main",
          "protected": true,
          "isDefault": true
      },
      {
          "name": "feature/new-api",
          "protected": false,
          "isDefault": false
      },
      {
          "name": "develop",
          "protected": true,
          "isDefault": false
      },
      {
          "name": "hotfix/security-patch",
          "protected": false,
          "isDefault": false
      }
  ]
  ```

  ```json Error Response theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  {
    "error": "Bad Request",
    "message": "Missing required parameters: owner and repo",
    "status": 400
  }
  ```

  ```json Not Found Response theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  {
    "error": "Not Found",
    "message": "Repository not found or you don't have access",
    "status": 404
  }
  ```
</ResponseExample>

## Error Codes

| Status Code | Error                 | Description                                              |
| ----------- | --------------------- | -------------------------------------------------------- |
| 200         | Success               | Branches retrieved successfully                          |
| 400         | Bad Request           | Missing required parameters: owner and repo              |
| 401         | Unauthorized          | Invalid or missing API key                               |
| 404         | Not Found             | GitHub token not found, expired, or repository not found |
| 502         | Bad Gateway           | GitHub API error occurred                                |
| 500         | Internal Server Error | Database or server error occurred                        |
