Compiling Sitecore CLI Commands
Sitecore CLI is a powerful tool that allows developers to interact with Sitecore Instance through a command line interface.
Sitecore has provided another interface called Sitecore CLI which includes huge list of cli commands which you can use for development, deployment and even DevOps processes especially helpful when working with Sitecore Headless (XM Cloud, JSS) or Sitecore Experience Platform in modern development workflows.
Since you will find many documents explaining how you can install and start with Sitecore CLI but in this blog I would like to compile all commands which I have used till now while development OR which are frequently used.
Downloads
You can download the Latest version of Sitecore CLI from this link.
If you have already installed CLI in your environment, then you can choose to upgrade to latest version, But if you are starting new then same link will guide you the steps to start with it.
Note: I have setup an alias in Powershell for dotnet sitecore to only sitecore, So if you have not setup it then you can use dotnet sitecore instead of sitecore for below mentioned commands.
Prerequisites
- Dotnet 8 version must be installed in your system.
- Sitecore Management Services package must be installed.
Initialization & Setup
1. Sitecore Init
Command > sitecore init
Description: Initializes Sitecore CLI in your project directory.
2. Sitecore login
Command > sitecore login --authority https://<sitecore identity server>
--cm https://<sitecore instance> --allow-write true
Description: Authenticates you with the Sitecore instance.
3. Using Client Secret
Command > sitecore login --authority https://<sitecore-identity-server>
--cm http://<sitecore-instance> --allow-write true --client-credentials true
--client-id <client-id> --client-secret <client-secret>
4. Sitecore Logout
Command > sitecore logout
Description: Logs out of the Sitecore instance.
Serialization
1. Enable Plugin
Command > dotnet sitecore plugin add -n Sitecore.DevEx.Extensibility.Serialization
Description: Enables serialization beyond version 4.
2. Sitecore Pull
Command > sitecore ser pull
Description: Pulls Sitecore items into your local filesystem (serialization folder).
3. Sitecore Pull (For specific module)
Command > sitecore ser pull --items-path src\Project\MySitecoreApp\serialization
4. Sitecore Push
Command > sitecore ser push
Description: Pushes local serialized items to Sitecore instance
5. Sitecore Push (To specific item path)
Command > dotnet sitecore publish item --path /sitecore/content/Home -sub -rel
6. Check Status
Command > sitecore ser status
Description: Shows which serialized items have changed.
7. Status Reset
Command > sitecore ser reset
Description: Resets the tracked state of serialized items. Most useful when
if serialization gets stuck or confused.
8. Check Difference
Command > sitecore ser diff -s <SOURCE_PATH> -d <DESTINATION_PATH>
Description: It will help you identify differences in item definitions
9. Validate Item
Command > sitecore ser validate
Description: It will allow you to check the issues in serialized items.
10. Watch
Command > sitecore ser watch
Description: You can use this command to set auto sync with your dev environment.
It actually watches for the changes in .yml file and keep it sync with
local or dev env.
Publishing
1. Enable the publishing feature
Command > sitecore plugin add -n Sitecore.DevEx.Extensibility.Publishing
2. Publish
Command > sitecore publish -c Prototype/
Description: It will publish all items from master to web database
3. Publish Specific item
Command > sitecore publish item --path /sitecore/content/Home -sub -rel
4. Publish Language Specfic
Command > sitecore publish -l en-US,en-CA
Create Package
1. Create sitecore package:
Command > sitecore package create --path .\packages\MyPackage.zip
--items-path src\serialization
Description: Creates a package based on a source directory.
2. Package install:
Command > sitecore package install --path .\packages\MyPackage.zip
Description: Install the package file
Miscellaneous
1. Create Template
Command > sitecore new template --name "Article Page"
--path "src/Project/MySitecoreApp/serialization/Templates"
2. Create Rendering
Command > sitecore new rendering --name "Hero Banner"
--path "src/Project/MySitecoreApp/serialization/Renderings"
3. Check CLI Version
Command > sitecore –version
Summary
In this blog I tried compiling most used commands for Sitecore CLI with their usage and description. Sitecore is upgrading to newer version of Sitecore CLI and it is strongly recommend to upgrade to latest version. You can follow this page link for more details with more/detailed command options https://doc.sitecore.com/xp/en/developers/latest/developer-tools/sitecore-command-line-interface.html
Comments
Post a Comment