---
title: "The CLI publish command"
slug: "the-cli-publish-command"
abstract: "Reference of the DevEx CLI publish command that publishes Sitecore Items."
---
# The CLI publish command

The [Sitecore publishing plugin](https://doc.sitecore.com/xp/en/developers/101/developer-tools/publishing-plugin.html "Publishing plugin") includes a `publish` command. This command publishes Sitecore Items.

The CLI supports all Sitecore publishing mechanisms. When you run the publish command, the CLI automatically uses the appropriate publishing method for the target environment:

- Experience Edge publishing when Experience Edge is configured as the publishing target.

- Publishing Service when Publishing Service is installed.

- Default publishing when neither Experience Edge nor Publishing Service is available.


To install the publishing plugin, run the following code:

```text
dotnet sitecore plugin add -n Sitecore.DevEx.Extensibility.Publishing

```

<details>
<summary><h2>Usage</h2></summary>

You can use the command as follows:

```text
dotnet sitecore publish [options]

```

> [!tip]
> Some Sitecore CLI command examples wrap items names and other strings containing spaces in single quotes for correct interpretation by PowerShell. If you use a different command-line shell, you might have to change single quotes to double quotes.

</details>

<details>
<summary><h2>Options</h2></summary>

You can use the following options with the `publish` command:

| Option | Required | Description |
| --- | --- | --- |
| `-n, --environment-name` | No | The Sitecore environment to use. Default: `default`. |
| `-c, --config` | No | Path to root `sitecore.config` directory (default: cwd). |
| `-l, --languages` | No | Comma-separated list of languages to publish. If unspecified, all languages are published. |
| `-p, --path` | No | *Deprecated*.<br><br>Sitecore item path or GUID to smart publish. If unspecified, then the entire database is published. |
| `-r, --republish` | No | Use republish. If unspecified, then smart-publish is used instead. |
| `-pt, --targets` | No | List of target databases to publish. If unspecified, it publishes to the default publishing target (the first one in the list). |
| `-v, --verbose` | No | Report additional diagnostic and performance data. |
| `-t, --trace` | No | Report additional diagnostic and performance data. |
| `-?, -h, --help` | No | Help for the command. |

</details>

<details>
<summary><h2>Examples</h2></summary>

The following are examples of the `publish` command use:

| Command | Result |
| --- | --- |
| Attempt to publish from the `samples` folder:<br><br>`dotnet sitecore publish` | Does not publish Sitecore items and returns the message: `error: Couldn't resolve a root configuration file (sitecore.json) in the current or any parent directory. Looks like the command may have been executed outside a Sitecore project?`. |
| Attempt to publish from the `samples` folder:<br><br>`dotnet sitecore publish -c Prototype/` | Publishes the Sitecore items from the folder `samples`. |
| `sitecore publish -n testEnv` | Publishes Sitecore items to the environment with the name `testEnv`. |
| `dotnet sitecore publish -l en-US,en-CA` | Publishes Sitecore items for only the specified languages (`en-US`,`en-CA`). |
| `dotnet sitecore publish -p '/sitecore/content/Home/Test Item'` | *Deprecated*. See the [item subcommand](https://doc.sitecore.com/xp/en/developers/101/developer-tools/the-cli-publish-command.html#UUID-27abbcf4-8326-d8ec-03b7-dccc710dd56b_section-idm4591327784929633273477612162).<br><br>Publishes only the item with path */sitecore/content/Home/Test Item*. |
| `dotnet sitecore publish -v` | Creates additional diagnostic and performance data, such as root config path or count of nodes with performance, for example, 73ms (8.1ms/node). |
| `dotnet sitecore publish -t` | Creates additional diagnostic and performance data, such as FSIndex: Loaded filesystem indexes in, for example, 70ms (9 metadatas) or created package of 1 trees in, for example, 1983ms (9 items; 220.3ms/node). |

</details>

<details>
<summary><h2>Subcommands</h2></summary>

The `publish` command has the following subcommands:

- `list-targets` - displays all the publishing targets defined for an environment.
- `item` - publishes a single item.

### The list-targets subcommand

The `list-targets` subcommand reads and lists all publishing targets defined for a Sitecore environment. The `list-targets` subcommand requires elevated permissions.

You can run the command as follows:

```text
dotnet sitecore publish list-targets [options]

```

You can use the following options with the `list-targets` subcommand:

| Option | Required | Description |
| --- | --- | --- |
| `-c, --config` | No | Path to root `sitecore.config` directory.<br><br>Default: current working directory. |
| `-n, --environment-name` | No | Named Sitecore environment to use.<br><br>Default: `'default'`. |
| `-v, --verbose` | No | Write additional diagnostic and performance data. |
| `-t, --trace` | No | Write additional diagnostic and performance data. |
| `-?, -h, --help` | No | `-?, -h, --help` |

### The item subcommand

The `item` subcommand publishes a single item. The `item` subcommand requires elevated permissions.

You can run the command as follows:

```text
dotnet sitecore publish item [options]

```

You can use the following options with the `item` subcommand:

| Option | Required | Description |
| --- | --- | --- |
| `-n, --environment-name` | No | The Sitecore environment to use.<br><br>Default: `default`. |
| `-c, --config` | No | Path to root `sitecore.config` directory.<br><br>Default: cwd. |
| `-l, --languages` | No | Comma-separated list of languages to publish. If unspecified, all languages are published. |
| `-p, --path` | No | Sitecore item path or GUID to smart publish. |
| `-r, --republish` | No | Use republish. If unspecified, then smart-publish is used instead. |
| `-pt, --targets` | No | List of target databases to publish. If unspecified, it publishes to the default publishing target (the first one in the list). |
| `-sub, --subitems` | No | Publish subitems.<br><br>Default: `false`. |
| `-rel, --related` | No | Publish related items.<br><br>Default: `false`. |
| `-v, --verbose` | No | Report additional diagnostic and performance data. |
| `-t, --trace` | No | Report additional diagnostic and performance data. |
| `-?, -h, --help` | No | Help for the command. |

For example, to publish a single item, including its subitems and related items, you run the following command:

```text
dotnet sitecore publish item --path /sitecore/content/Home -sub -rel

```

</details>