Skip to content
repo-sdk
Esc
navigateopen⌘Jpreview
On this page

Working with branches

List a repository's branches as normalized Branch objects.

branches.list / branches.listAll page through a repository’s branches as normalized Branch objects, on every provider.

Listing branches

branches.list returns one Page<Branch>; branches.listAll follows cursors and yields every branch. Both require a repo:

const { data: branches } = await client.branches.list({ repo: 'capawesome-team/repo-sdk' });

for await (const branch of client.branches.listAll({ repo: 'capawesome-team/repo-sdk' })) {
  console.log(branch.name, branch.sha);
}

The normalized Branch

PropType
name?string

The branch name (without the refs/heads/ prefix).

Typestring
sha?string

The commit SHA the branch currently points at.

Typestring
raw?unknown

The untouched provider payload.

Typeunknown

The model is intentionally minimal — provider-specific extras such as protection flags are available on raw. To find the default branch, use the repository itself:

const repo = await client.repos.get({ repo: 'capawesome-team/repo-sdk' });
console.log(repo.defaultBranch); // e.g. 'main' (undefined for an empty repository)

Getting a single branch

branches.get fetches one branch by its exact name and throws a RepoError with code: 'not_found' on a miss:

const branch = await client.branches.get({ repo: 'capawesome-team/repo-sdk', name: 'main' });
console.log(branch.sha); // the branch's current tip

Next: Searching refs

Prefix-match branches, tags, and commit SHAs — built for autocompletion.

Was this page helpful?