Contentstack provides Branches to create multiple copies of your stack content. By default, stacks have a main branch. You can fork a branch from the main branch (parent branch) to create a new branch (child branch).
Contentstack lets you list, create, delete, compare, and merge Branches using the CLI. You can compare two branches and merge the two with the desired changes into a single branch.
This step-by-step guides you on how to create, update, delete, compare, and merge Branches using the CLI. In the CLI, the base branch refers to the target branch, while the compare branch is the source branch.
Note: Contact your organization administrator for more details.
You can list the branches in a stack, create a new branch in a stack from a base branch, and delete an existing branch from a stack.
csdx cm:branchesYou can see the branches for the specific stack displayed.
Alternatively, you can pass the Stack API key in the command as given below:
csdx cm:branches --stack-api-key <value>You can also view the list in a detailed view using the verbose flag:
csdx cm:branches --verboseUsage
csdx cm:branchesor
csdx cm:branches -k <value>or
csdx cm:branches --stack-api-key <value>Options
csdx cm:branches:createYou have successfully created a new branch.
Alternatively, you can pass the Stack API key, source, and UID in the command as given below:
csdx cm:branches:create --stack-api-key <value> --source <value> --uid <value>Limitations
Usage
csdx cm:branches:createor
csdx cm:branches:create --stack-api-key <value> --source <value> --uid <value>Options
csdx cm:branches:deleteYou have successfully deleted a branch.
Alternatively, you can pass the Stack API key and UID in the command as given below, and then in the following step, when prompted, enter the name of the branch to confirm the deletion.
csdx cm:branches:delete --stack-api-key <value> --uid <value>To skip confirmation and delete the branch forcefully:
csdx cm:branches:delete --stack-api-key <value> --uid <value> --yesUsage
csdx cm:branches:deleteor
csdx cm:branches:delete --stack-api-key <value> --uid <value>or
csdx cm:branches:delete --stack-api-key <value> --uid <value> --yesOptions
Examples
csdx cm:branches --stack-api-key bltxxxxxxxx7csdx cm:branches:create --stack-api-key bltxxxxxxxx7 --source test1 --uid test2csdx cm:branches:delete --stack-api-key bltxxxxxxxx7 --uid test2You can set, get, or remove the default base branch for a stack. This will be used as the default base branch when performing a compare or merge command and will act as the target branch where the final changes will be merged during the merge operation.
csdx config:set:base-branchAlternatively, you can pass the Stack API key and base branch name in the command as given below:
csdx config:set:base-branch --stack-api-key <value> --base-branch <value>Usage
csdx config:set:base-branchor
csdx config:set:base-branch --stack-api-key <value> --base-branch <value>Options
csdx config:get:base-branchThe base branch will be displayed along with the Stack API key.
Usage
csdx config:get:base-branchcsdx config:remove:base-branchAlternatively, you can pass the Stack API key in the command as given below, and then when prompted, enter Y to remove the base branch.
csdx config:remove:base-branch --stack-api-key <value>To forcefully remove the base branch by bypassing the confirmation step, pass the command as given below:
csdx config:remove:base-branch --stack-api-key <value> --yesUsage
csdx config:remove:base-branchor
csdx config:remove:base-branch --stack-api-key <value>or
csdx config:remove:base-branch --stack-api-key <value> --yesOptions
Examples
csdx config:set:base-branch --stack-api-key bltxxxxxxxx7 --base-branch test2csdx config:remove:base-branch --stack-api-key bltxxxxxxxx7 --yesFollow the steps below to compare two branches:
csdx cm:branches:diffAlternatively, you can pass the Stack API key, base branch (target branch), and compare branch (source branch) in the command as given below:
csdx cm:branches:diff --stack-api-key <value> --base-branch <value> --compare-branch <value> --module <value>Note: To choose a base branch other than the default, specify the --base-branch flag as given in the command above.
You get the comparison results as displayed below:

The CLI displays the branch comparison summary along with the modules affected.
csdx cm:branches:diff --stack-api-key <value> --base-branch <value> --compare-branch <value> --format detailed-textYou get the detailed comparison results as displayed below:

This displays the branch comparison summary, showing modules and the affected sub-modules. In our example, the content types are displayed along with their fields.
The comparison results are distinguished based on the following:
Usage
csdx cm:branches:diffor
csdx cm:branches:diff --stack-api-key <value> --base-branch <value> --compare-branch <value> --module <value>or
csdx cm:branches:diff --stack-api-key <value> --base-branch <value> --compare-branch <value> --module <value> --format <value>Options
Examples
csdx cm:branches:diff --stack-api-key bltxxxxxxxx --base-branch main --compare-branch develop --module content-typescsdx cm:branches:diff --stack-api-key bltxxxxxxxx --base-branch main --compare-branch develop --module global-fields --format detailed-textcsdx cm:branches:diff --stack-api-key bltxxxxxxxx --base-branch main --compare-branch develop --module global-fields --format detailed-text --csv-path "/path/to/folder"Note: When you use --format "detailed-text", the command also generates a CSV file for easier analysis and reporting of branch differences. You can use the --csv-path flag to choose where the file is saved. If you select --format "compact-text", the --csv-path flag is ignored.
Follow the steps below to merge two branches:
csdx cm:branches:mergeAlternatively, you can pass the Stack API key, base branch (target branch), and compare branch (source branch) in the command as given below:
csdx cm:branches:merge --stack-api-key <value> --base-branch <value> --compare-branch <value>Note: To choose a base branch other than the default, specify the --base-branch flag as given in the command above.
The branches' compare results will be displayed for individual modules as Content Types Summary and Global Fields Summary.
The following table contains an example of field changes to a content type between the base branch and compare branch, and explains how the changes are merged based on the merge strategy you choose:
| Base Branch | Compare Branch | Merge, Prefer Base | Merge, Prefer Compare | Overwrite with Compare | Is conflict? |
|---|---|---|---|---|---|
Title (unchanged) | Title (unchanged) | Title (unchanged) | Title (unchanged) | Title (unchanged) | No |
Categories (present) | (not present) | Categories (from Base) | Categories (from Base) |
| No |
Feature B (renamed/reconfigured) | Feature C (renamed/reconfigured) | Feature B (from Base) | Feature C (from Compare) | Feature C (from Compare) | Yes |
(not present) | SEO Description (present) | SEO Description (from Compare) | SEO Description (from Compare) | SEO Description (from Compare) | No |
Topics |
| Topics (from Base) | Topics (from Base) | (removed from Base) | No |
The following table contains the content types in the base branch and compare branch, explaining how data is merged based on the merge strategy preference you choose:
| Base Branch | Compare Branch | Merge New in Compare Only | Merge Modified Only, Prefer Base | Merge, Modified Only, Prefer Compare |
|---|---|---|---|---|
Title | Title | Title | Title | Title |
Categories |
| Categories | Categories | Categories |
Feature B | Feature C | Feature B | Feature B | Feature C |
| SEO Description |
| SEO Description | SEO Description |
Topics |
| Topics | Topics |
|


Note: To ignore the changes in the compare branch for a specific content type, select the Ignore(Use Base) option for that content type.
Tip: Use the arrow keys to move along the table cells and then hit the spacebar to make the selection.

Note: To ignore the changes in the compare branch for a specific global field, select the Ignore(Use Base) option for that global field.
With this, the merge operation is completed, and the Entry Migration files generated are placed in the “YYYYMMDDHHMMSS_bltxxx” folder under merge_scripts folder in the current working directory.
Usage
csdx cm:branches:mergeor
csdx cm:branches:merge --stack-api-key <value> --base-branch <value> --compare-branch <value>Options
Examples
csdx cm:branches:merge --stack-api-key bltxxxxxxxx --compare-branch feature-branchcsdx cm:branches:merge --export-summary-path "/file/path"