---
title: "[Contentstack Command-line Interface (CLI)] - Migrate and Overwrite Content in the Same Stack"
description: Migrate and overwrite existing content in the same Contentstack stack using the Contentstack CLI entries module.
url: https://www.contentstack.com/docs/developers/cli/migrate-and-overwrite-content-in-the-same-stack
product: Contentstack
doc_type: how-to
audience:
  - developers
version: latest
last_updated: 2026-03-25
---

# [Contentstack Command-line Interface (CLI)] - Migrate and Overwrite Content in the Same Stack

This page explains how to use the Contentstack Command-line Interface (CLI) to migrate content into the same stack while overwriting existing data, intended for developers who need to avoid duplicate content and keep entries and dependencies consistent.

## Migrate and Overwrite Content in the Same Stack

Use this approach when the same stack already contains content, and you want to overwrite existing data instead of creating duplicates.

This method imports entries and their dependencies, including assets, extensions, marketplace apps, and taxonomies, using the entries module, ensuring content remains consistent across the stack.

## Prerequisites

Before you begin, ensure the following:
- You have exported content from the stack to a local folder.
- You are authenticated using the CLI:
```
csdx auth:login
```
- You have the **Stack API key** of the target stack.
- You have the necessary [permissions](/docs/developers/invite-users-and-assign-roles/types-of-roles).

## Step 1: Export Content (If Not Already Exported)

This command exports content from your stack.

```
csdx cm:stacks:export -k  -d ./export --branch main
```

Replace `<stack_api_key>` with your actual stack API key.

After the export completes, note the branch folder path (for example, `./export/main`). You will use this path in the next steps.

## Step 2: Run Import Setup

The `import-setup` command generates mapper files and creates a backup of the existing entries in your stack.

```
csdx cm:stacks:import-setup -k  -d ./export/main --module entries
```

**Replace:**
- `<stack_api_key>` with your stack API key.
- `./export/main` with your actual export path if different.

After the command runs, the CLI displays the backup folder path.

**Example output:**

The backup folder has been created at '`./_backup_123`'

Copy the backup path shown in your terminal. Use this path in the next step.

## Step 3: Import with Overwrite

This command imports the content and replaces existing entries.

```
csdx cm:stacks:import \
-k  \
-d ./export/main \
--backup-dir ./backup_123 \
--replace-existing \
--module entries
```

**Replace:**
- `<stack_api_key>` with your stack API key.
- `./backup_123` with the exact backup path generated in Step 2.
- `./export/main` if your export path is different.

## Branch-Specific Import

If importing into a specific branch, use:
- `--branch <branch_name>`
- `--branch-alias <alias_name>`

## Data Overwrite Considerations

Overwriting updates existing entries in the stack.
- The backup created during `import-setup` is your recovery reference.
- Always use the exact backup directory path generated by the CLI.
- Do not manually modify backup files.

If you need to revert changes, use the backup folder generated during [Step 2 ](/docs/developers/cli/migrate-and-overwrite-content-in-the-same-stack#step-2-run-import-setup)to restore previous content.

## Common questions

**Q: When should I use `--replace-existing`?**  
A: Use this approach when the same stack already contains content, and you want to overwrite existing data instead of creating duplicates.

**Q: What is the purpose of `import-setup`?**  
A: The `import-setup` command generates mapper files and creates a backup of the existing entries in your stack.

**Q: What should I do if I need to revert changes after overwriting?**  
A: If you need to revert changes, use the backup folder generated during Step 2 to restore previous content.

**Q: Can I import into a specific branch?**  
A: If importing into a specific branch, use `--branch <branch_name>` and `--branch-alias <alias_name>`.