Sample - GitHub REST API
GET/repos/{owner}/{repo}/branches/{branch}

Get a repository branch

Retrieves a specific branch from a repository, including its latest commit, links, and protection configuration. Supply branch as the branch name without wildcard characters; use the GraphQL API when you need wildcard matching.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

3 parameters
ownerstringrequired
The account owner of the repository; the name is not case sensitive.
repostringrequired
The repository name without the `.git` extension; the name is not case sensitive.
branchstringrequired
The name of the branch to retrieve. It cannot contain wildcard characters.

3 status codes
200Returns a branch object containing the branch name, latest commit details, repository links, protection configuration, and protection status.
namestringrequired
commitobjectrequired
Commit
_linksobjectrequired
protectedbooleanrequired
protectionobjectrequired
Branch Protection
protection_urlstringrequired
patternstringoptional
required_approving_review_countintegeroptional
301Returned when the repository has moved permanently.
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
404Returned when the specified repository or branch cannot be found.
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional

Error handling

A 301 is returned when the repository has moved permanently. A 404 is returned when the repository or branch cannot be found. branch must not contain wildcard characters.