---
title: "Upsert branch"
method: PUT
path: "/api/v2/code-refs/repositories/{repo}/branches/{branch}"
tags: ["Code references"]
---

# Upsert branch

`PUT /api/v2/code-refs/repositories/{repo}/branches/{branch}`

Create a new branch if it doesn't exist, or update the branch if it already exists.

## Path parameters

- `repo` string, string, required — The repository name
- `branch` string, string, required — The URL-encoded branch name

## Request body

- PutBranch
  - `name` string, required — The branch name
  - `head` string, required — An ID representing the branch HEAD. For example, a commit SHA.
  - `updateSequenceId` integer — An optional ID used to prevent older data from overwriting newer data. If no sequence ID is included, the newly submitted data will always be saved.
  - `syncTime` integer, required
  - `references` ReferenceRep[] — An array of flag references found on the branch
    - `path` string, required — File path of the reference
    - `hint` string — Programming language used in the file
    - `hunks` HunkRep[], required
      - `startingLineNumber` integer, required — Line number of beginning of code reference hunk
      - `lines` string — Contextual lines of code that include the referenced feature flag
      - `projKey` string — The project key
      - `flagKey` string — The feature flag key
      - `aliases` string[] — An array of flag key aliases
  - `commitTime` integer

## Response `200`

Action succeeded

## Other responses

- `400` — Invalid request
- `401` — Invalid access token
- `403` — Forbidden
- `404` — Invalid resource identifier
- `409` — Status conflict
- `429` — Rate limited

---

[API](https://skmtc.dev/launchdarkly/apis/launchdarkly-rest-api.md) · [All operations](https://skmtc.dev/launchdarkly/apis/launchdarkly-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/launchdarkly/launchdarkly-rest-api/revisions/69c5c9aafe78/schema)
