> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/harness-platform/use-harness-cli/harness-cli/harness-cli-commands/code-repository-commands.md).

# Code Repository

Harness Code Repository provides built-in git hosting within the Harness platform. The CLI gives you full access to repository management, pull request workflows, code review, branch operations, and commit history without switching to a browser or external git host. Use these commands to automate code review workflows, manage branches at scale, and integrate repository operations into scripts and pipelines.

This page covers all Code Repository resources and actions available in the CLI.

***

### What you will learn in this topic <a href="#what-you-will-learn-in-this-topic" id="what-you-will-learn-in-this-topic"></a>

By the end of this page, you will know how to:

* List, create, update, and delete repositories.
* Open, update, merge, and close pull requests from the terminal.
* List the pull requests you authored and the pull requests that await your review across every repository in scope.
* Submit review decisions and manage reviewers and codeowners.
* Retrieve Harness Code AI review insights, such as risk summaries, suggested reviewers, and suggested labels.
* View pull request activity, manage comments, and inspect status checks.
* Create and manage branches and tags.
* Inspect commit history and individual commit details.

***

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

* **Harness CLI installed and authenticated:** For setup steps, see [Install and upgrade](/harness-platform/use-harness-cli/harness-cli/install-and-upgrade.md) and [Authenticate](/harness-platform/use-harness-cli/harness-cli/authenticate.md).
* **Project scope configured:** Code Repository resources require `--org` and `--project`. Set them in your profile or pass them on each command.

***

### Resource identifiers <a href="#resource-identifiers" id="resource-identifiers"></a>

Repositories are top-level resources. Pull requests, branches, commits, and tags live inside a repository, so they use compound identifiers that combine the repository with the child resource:

* **`<repo>/<pr_number>`:** A pull request in a repository.
* **`<repo>/<branch>`:** A branch in a repository.
* **`<repo>/<sha>`:** A commit in a repository.
* **`<repo>/<pr_number>/<reviewer_id>`:** A reviewer on a pull request.
* **`<repo>/<pr_number>/<comment_id>`:** A comment on a pull request.

Leave the slash in a compound identifier unencoded. For the `--set`, `--del`, `-f`, `--format`, paging, and scope conventions that apply to every command on this page, see [Global flags and output](/harness-platform/use-harness-cli/harness-cli/global-flags-and-output.md).

***

### Repositories <a href="#repositories" id="repositories"></a>

A repository stores your source code and tracks changes through git. Each repository belongs to a project and has a default branch, description, and access settings. Use repository commands to create new projects, update configurations, or remove archived code.

#### List repositories <a href="#list-repositories" id="list-repositories"></a>

View all repositories in your project to browse available codebases. Repository is a multi-level noun, so it also supports account and organization scope.

```sh
harness list repository
harness list repository --all --format json
harness list repository --search "<repository_name>"
harness list repository --columns "name,id,defaultBranch"
harness list repository --level account
```

#### Get repository details <a href="#get-repository-details" id="get-repository-details"></a>

Retrieve the full metadata for a repository, including its default branch, size, clone URLs, and creation date.

```sh
harness get repository <repository_id>
harness get repository <repository_id> --format json
```

#### Create a repository <a href="#create-a-repository" id="create-a-repository"></a>

Create a new empty repository. Only `identifier` is required. The `default_branch`, `description`, and `is_public` fields are optional.

```sh
harness create repository \
  --set identifier=<repository_id> \
  --set default_branch=main \
  --set description="<description>" \
  --set is_public=true
```

#### Update a repository <a href="#update-a-repository" id="update-a-repository"></a>

Modify the `description`, `default_branch`, or `is_public` setting on an existing repository.

```sh
harness update repository <repository_id> --set description="<description>"
harness update repository <repository_id> --set default_branch=<branch_name>
harness update repository <repository_id> --set is_public=false
```

#### Delete a repository <a href="#delete-a-repository" id="delete-a-repository"></a>

Remove a repository and all its contents, branches, and history. This action is irreversible.

```sh
harness delete repository <repository_id>
```

***

### Pull requests <a href="#pull-requests" id="pull-requests"></a>

A pull request proposes changes from one branch to another for code review. Pull requests track the discussion, review decisions, and merge status of a set of commits. Use the CLI to manage the entire pull request lifecycle from creation through merge.

#### List pull requests <a href="#list-pull-requests" id="list-pull-requests"></a>

View pull requests in a repository. Pass the repository identifier as a positional argument.

```sh
harness list pr <repository_id>
harness list pr <repository_id> --state open
harness list pr <repository_id> --author <email|uid|id>
harness list pr <repository_id> --search "<search_term>"
harness list pr <repository_id> --created-after <date>
harness list pr <repository_id> --sort <field> --order <asc|desc>
harness list pr <repository_id> --all --format json
```

#### List your own pull requests <a href="#list-your-own-pull-requests" id="list-your-own-pull-requests"></a>

List the pull requests you authored across every repository in scope. This command does not take a repository identifier.

```sh
harness list pr:mine
harness list pr:mine --state open
harness list pr:mine --created-after <date> --created-before <date>
```

#### List pull requests awaiting your review <a href="#list-pull-requests-awaiting-your-review" id="list-pull-requests-awaiting-your-review"></a>

List the pull requests that await your review across every repository in scope.

```sh
harness list pr:review_pending
harness list pr:review_pending --state open
harness list pr:review_pending --created-after <date> --created-before <date>
```

#### Get pull request details <a href="#get-pull-request-details" id="get-pull-request-details"></a>

Retrieve the full metadata for a pull request using the `<repo_id>/<pr_number>` format. The default output is rich text produced by the workflow formatter.

```sh
harness get pr <repository_id>/<pr_number>
harness get pr <repository_id>/<pr_number> --format json
```

#### Create a pull request <a href="#create-a-pull-request" id="create-a-pull-request"></a>

Open a new pull request from a source branch to a target branch. Pass the repository as a positional argument. To supply the description body from a file, use `-f`.

```sh
harness create pr <repository_id> \
  --set title="<pr_title>" \
  --set source_branch=<source_branch> \
  --set target_branch=<target_branch>

harness create pr <repository_id> \
  --set title="<pr_title>" \
  --set source_branch=<source_branch> \
  --set target_branch=<target_branch> \
  -f desc.md
```

#### Update a pull request <a href="#update-a-pull-request" id="update-a-pull-request"></a>

Modify the title, description, draft state, or other editable fields on an existing pull request.

```sh
harness update pr <repository_id>/<pr_number> --set title="<updated_title>"
harness update pr <repository_id>/<pr_number> --set description="<updated_description>"
harness update pr <repository_id>/<pr_number> --set is_draft=false
```

#### Merge a pull request <a href="#merge-a-pull-request" id="merge-a-pull-request"></a>

Merge an approved pull request into its target branch. Use `--method` to select the merge strategy, `--delete-branch` to remove the source branch after the merge, and `--dry-run` to validate the merge without applying it.

```sh
harness execute pr:merge <repository_id>/<pr_number>
harness execute pr:merge <repository_id>/<pr_number> --method merge|squash|rebase|fast-forward
harness execute pr:merge <repository_id>/<pr_number> --method squash --delete-branch
harness execute pr:merge <repository_id>/<pr_number> --dry-run
```

#### Close a pull request <a href="#close-a-pull-request" id="close-a-pull-request"></a>

Close a pull request without merging its changes. Use this to abandon proposals that are no longer relevant.

```sh
harness execute pr:close <repository_id>/<pr_number>
```

***

### Reviews, reviewers, and codeowners <a href="#reviews-reviewers-and-codeowners" id="reviews-reviewers-and-codeowners"></a>

A review records a decision on a pull request. Reviewers are the principals asked to review the changes, and codeowners are the reviewers that repository ownership rules assign automatically based on the files a pull request touches.

#### Submit a review decision <a href="#submit-a-review-decision" id="submit-a-review-decision"></a>

Approve a pull request or request changes on it.

```sh
harness execute pr:review <repository_id>/<pr_number> --decision approve
harness execute pr:review <repository_id>/<pr_number> --decision changereq
```

#### List Code principals <a href="#list-code-principals" id="list-code-principals"></a>

List the Code principals, such as users and service accounts, that are available in scope. Use this to look up the identifier of a reviewer before you add them.

```sh
harness list code_principal
harness list code_principal --search "<search_term>"
```

#### List reviewers <a href="#list-reviewers" id="list-reviewers"></a>

View the reviewers on a pull request, along with each reviewer's decision, type, and the principal who added them.

```sh
harness list pr_reviewer <repository_id>/<pr_number>
harness list pr_reviewer <repository_id>/<pr_number> --format json
```

#### Add a reviewer <a href="#add-a-reviewer" id="add-a-reviewer"></a>

Add a reviewer to a pull request. The CLI resolves the value you pass to `--reviewer` automatically, so you can use an email address, a UID, or an identifier.

```sh
harness create pr_reviewer <repository_id>/<pr_number> --reviewer <email|uid|id>
```

#### Remove a reviewer <a href="#remove-a-reviewer" id="remove-a-reviewer"></a>

Remove a reviewer from a pull request using the `<repo_id>/<pr_number>/<reviewer_id>` format.

```sh
harness delete pr_reviewer <repository_id>/<pr_number>/<reviewer_id>
```

#### List codeowners <a href="#list-codeowners" id="list-codeowners"></a>

View the codeowners evaluated on a pull request, including the matched pattern, the owner, and the review decision.

```sh
harness list pr_codeowner <repository_id>/<pr_number>
harness list pr_codeowner <repository_id>/<pr_number> --format json
```

***

### AI review insights <a href="#ai-review-insights" id="ai-review-insights"></a>

Harness Code AI review analyzes a pull request and produces review guidance: a risk summary, risk-bucketed file groups, suggested reviewers, suggested labels, and success-criteria results. Use these commands to pull that guidance into the terminal or into a script.

#### Get the risk summary insight <a href="#get-the-risk-summary-insight" id="get-the-risk-summary-insight"></a>

Retrieve the risk summary insight for a pull request.

```sh
harness get pr:insight <repository_id>/<pr_number>
harness get pr:insight <repository_id>/<pr_number> --format json
```

#### Get risk-bucketed review groups <a href="#get-risk-bucketed-review-groups" id="get-risk-bucketed-review-groups"></a>

Retrieve the risk-bucketed file groups for review. The default output is formatted for terminal display.

```sh
harness get pr:review_group <repository_id>/<pr_number>
harness get pr:review_group <repository_id>/<pr_number> --format json
```

#### List suggested reviewers <a href="#list-suggested-reviewers" id="list-suggested-reviewers"></a>

List the reviewers that AI review suggests for a pull request.

```sh
harness list pr_suggested_reviewer <repository_id>/<pr_number>
```

#### List suggested labels <a href="#list-suggested-labels" id="list-suggested-labels"></a>

List the labels that AI review suggests for a pull request.

```sh
harness list pr_suggested_label <repository_id>/<pr_number>
```

#### List success-criteria results <a href="#list-success-criteria-results" id="list-success-criteria-results"></a>

List the AI review success-criteria results for a pull request.

```sh
harness list pr_success_criterion <repository_id>/<pr_number>
```

***

### Pull request activity, comments, and checks <a href="#pull-request-activity-comments-and-checks" id="pull-request-activity-comments-and-checks"></a>

Pull request activity is the complete log of events on a pull request: comments, review decisions, status changes, and commit updates. Comments carry the review discussion, and checks report the status results that pipelines and other integrations publish.

#### List pull request activity <a href="#list-pull-request-activity" id="list-pull-request-activity"></a>

View the activity timeline for a pull request. Filter the timeline with `--kind` and `--type`.

```sh
harness list pr_activity <repository_id>/<pr_number>
harness list pr_activity <repository_id>/<pr_number> --kind <kind> --type <type>
harness list pr_activity <repository_id>/<pr_number> --format json
```

#### List comments <a href="#list-comments" id="list-comments"></a>

View the comments on a pull request.

```sh
harness list pr_comment <repository_id>/<pr_number>
harness list pr_comment <repository_id>/<pr_number> --format json
```

#### Post a comment <a href="#post-a-comment" id="post-a-comment"></a>

Post a comment on a pull request. Supply the comment body with `-f <file>` or on stdin. To reply within an existing thread, pass the parent comment identifier to `--reply-to`.

```sh
harness create pr_comment <repository_id>/<pr_number> -f comment.md
echo "<comment_text>" | harness create pr_comment <repository_id>/<pr_number> -f -
harness create pr_comment <repository_id>/<pr_number> -f reply.md --reply-to <comment_id>
```

#### Update a comment <a href="#update-a-comment" id="update-a-comment"></a>

Edit the text of an existing comment using the `<repo_id>/<pr_number>/<comment_id>` format.

```sh
harness update pr_comment <repository_id>/<pr_number>/<comment_id> --text "<updated_text>"
```

#### Delete a comment <a href="#delete-a-comment" id="delete-a-comment"></a>

Remove a comment from a pull request.

```sh
harness delete pr_comment <repository_id>/<pr_number>/<comment_id>
```

#### List pull request checks <a href="#list-pull-request-checks" id="list-pull-request-checks"></a>

View the status checks on a pull request. When a check reports them, the output includes the pipeline identifier, the execution identifier, and the stage.

```sh
harness list pr_check <repository_id>/<pr_number>
harness list pr_check <repository_id>/<pr_number> --format json
```

#### List commit checks <a href="#list-commit-checks" id="list-commit-checks"></a>

View the status checks on a specific commit SHA.

```sh
harness list commit_check <repository_id>/<commit_sha>
harness list commit_check <repository_id>/<commit_sha> --search "<search_term>"
```

***

### Branches <a href="#branches" id="branches"></a>

A branch is a named pointer to a commit in a repository. Branches let multiple developers work on different features simultaneously without interfering with each other. Use branch commands to create feature branches, inspect branch state, or clean up merged branches.

#### List branches <a href="#list-branches" id="list-branches"></a>

View all branches in a repository to see active development work. Pass the repository as a positional argument.

```sh
harness list branch <repository_id>
harness list branch <repository_id> --search "<search_term>"
harness list branch <repository_id> --all --format json
```

#### Get branch details <a href="#get-branch-details" id="get-branch-details"></a>

Retrieve metadata for a specific branch using the `<repo_id>/<branch_name>` format.

```sh
harness get branch <repository_id>/<branch_name>
harness get branch <repository_id>/<branch_name> --format json
```

#### Create a branch <a href="#create-a-branch" id="create-a-branch"></a>

Create a new branch from a specified target commit or branch. Pass the repository as a positional argument.

```sh
harness create branch <repository_id> \
  --set name=<branch_name> \
  --set target=<target_branch_or_sha>
```

#### Delete a branch <a href="#delete-a-branch" id="delete-a-branch"></a>

Remove a branch that has been merged or is no longer needed.

```sh
harness delete branch <repository_id>/<branch_name>
```

***

### Commits <a href="#commits" id="commits"></a>

A commit is an immutable snapshot of repository contents at a point in time. Each commit records who made the change, when, and why (through the commit message). Use commit commands to browse history and inspect individual changes for debugging or auditing.

#### List recent commits <a href="#list-recent-commits" id="list-recent-commits"></a>

View the commit history for a repository. Pass the repository as a positional argument. Use `--branch` to list commits on a specific ref and `--path` to list commits that touch a specific file.

```sh
harness list commit <repository_id>
harness list commit <repository_id> --branch <ref>
harness list commit <repository_id> --path <file_path>
harness list commit <repository_id> --limit 20 --format json
```

#### List commits in a pull request <a href="#list-commits-in-a-pull-request" id="list-commits-in-a-pull-request"></a>

View only the commits that a pull request contains.

```sh
harness list pr_commit <repository_id>/<pr_number>
harness list pr_commit <repository_id>/<pr_number> --format json
```

#### Get commit details <a href="#get-commit-details" id="get-commit-details"></a>

Retrieve the full metadata for a specific commit using the `<repo_id>/<sha>` format.

```sh
harness get commit <repository_id>/<commit_sha>
harness get commit <repository_id>/<commit_sha> --format json
```

***

### Tags <a href="#tags" id="tags"></a>

A tag marks a specific commit with a human-readable name, typically used to identify release versions. Unlike branches, tags do not move forward with new commits. Use tags to create stable release markers that you can reference in deployments and changelogs.

#### List tags <a href="#list-tags" id="list-tags"></a>

View all tags in a repository to see the release history. Pass the repository as a positional argument.

```sh
harness list tag <repository_id>
harness list tag <repository_id> --search "<search_term>"
harness list tag <repository_id> --format json
```

#### Create a tag <a href="#create-a-tag" id="create-a-tag"></a>

Create a new tag pointing to a specific commit. Pass the repository as a positional argument.

```sh
harness create tag <repository_id> \
  --set name=<tag_name> \
  --set target=<commit_sha>
```

#### Delete a tag <a href="#delete-a-tag" id="delete-a-tag"></a>

Remove a tag that was created in error or is no longer relevant. The underlying commit remains unchanged.

```sh
harness delete tag <repository_id>/<tag_name>
```

***

### Related articles <a href="#related-articles" id="related-articles"></a>

* [Harness CLI for Code Repository](/code-repository/use-harness-code/code-repository-cli-commands/harness-cli.md): Install, authenticate, and run a guided review and merge workflow.
* [Continuous Delivery](/harness-platform/use-harness-cli/harness-cli/harness-cli-commands/cd-and-pipeline-commands.md): Manage pipelines and deployment resources.
* [Platform](/harness-platform/use-harness-cli/harness-cli/harness-cli-commands/platform-commands.md): Manage account resources, connectors, and secrets.
