Manage branches with the CLI
To install the magento-cloud
CLI, see the Cloud CLI reference. After you install the magento-cloud
CLI and set up SSH keys for remote access to your cloud infrastructure, you can use magento-cloud
CLI commands to manage the environments for your projects. For information about the environment architecture, see Starter architecture or Pro architecture.
To manage the branches and environments with the Cloud Console, see Manage branches with the Cloud Console.
Use CLI commands
The magento-cloud
CLI commands are similar to Git commands. You can use them to connect to your project and manage your environments. Although you can run the commands from any directory, it is recommended that you run them from a project directory. When run from a project directory, you can omit the -p <project-ID>
parameter. See the Cloud CLI reference.
Clone the project
The following instructions use a combination of magento-cloud
CLI commands and Git commands to clone your project to your local workstation. To see a full list of magento-cloud
CLI commands, use the magento-cloud list
command.
magento-cloud environment:branch <branch-name>
command for the environment to become active. Alternatively, you can use the Cloud Console to create active environments. See Cloud CLI reference.To clone a project master
environment:
-
Log in to your local workstation with a file system owner account.
-
Change to the web server or virtual host docroot directory.
-
Log in using the
magento-cloud
CLI.code language-bash magento-cloud login
-
List your projects.
code language-bash magento-cloud project:list
-
Clone a project.
code language-bash magento-cloud project:get <project-ID>
When prompted, provide a directory name.
-
Change to the
magento2
directory. -
List available environments for the project.
code language-bash magento-cloud environment:list
note important IMPORTANT The magento-cloud environment:list
command displays environment hierarchies, whereas thegit branch
command does not. -
Fetch the remote branches.
code language-bash git fetch origin
-
Pull updated code.
code language-bash git pull origin <environment-ID>
Create a branch for development
After cloning your project and updating the Adobe Commerce administrator account configuration, you can branch for development. As stated earlier, you must create an environment using the magento-cloud environment:branch <branch-name>
command or the Cloud Console for the environment to become active.
To create a development branch:
-
On your local workstation, change to your project directory.
-
Create an environment based on the branch recommended for your project workflow.
code language-bash magento-cloud branch <new-environment-name> integration
-
Update dependencies.
code language-bash composer --no-ansi --no-interaction install --no-progress --prefer-dist --optimize-autoloader
-
[optional] Create a backup of the environment.
Merge a branch
After completing development, merge this branch to the parent:
-
Commit and push code changes:
code language-bash git add -A && git commit -m "Add message here"
code language-bash git push origin <branch-name>
-
Merge with the parent environment:
code language-bash magento-cloud environment:merge <environment-ID>
Delete an environment
Only delete an environment if you are certain that you no longer need it. You cannot recover an environment after you delete it.
master
branch of any project.You must be a project administrator, environment administrator, or Account Owner to perform this task. See Manage user access to Cloud projects.
When you delete an environment, the environment is set to inactive. The code is still available in the Git branch, but no longer contains the services or the database. To delete the environment completely, you must also delete the corresponding remote Git branch.
To delete an environment:
-
On your local workstation, change to your project directory.
-
Fetch updates from the remote server.
code language-bash git fetch
-
Delete the environment branch.
code language-bash magento-cloud environment:delete <environment-ID>
Optionally, you can delete more than one environment at a time by adding multiple environment IDs to the delete command.
code language-bash magento-cloud environment:delete <environment-1-ID> <environment-2-ID>
-
Respond to the prompts to delete the local environment and the corresponding remote environment.
code language-none The environment <environment-ID> is currently active: deleting it will delete all associated data. Are you sure you want to delete the environment <environment-ID>? [Y/n]
Deleting the environment places it in an inactive state.
code language-none Delete the remote Git branch too? [Y/n]
Deleting the remote Git branch removes the environment from the project.
-
Wait for the environment to delete.
code language-none Deleting environment <environment-ID> Waiting for the activity... Deleting environment <project-id>-<environment-ID>-xxxxxx [============================] 1 min (complete) Activity ID succeeded Deleted remote Git branch <environment-ID> Run git fetch --prune to remove deleted branches from your local cache.
magento-cloud environment:activate
command.Interact with remote environments
After you set up SSH keys, you can connect from your local workspace to a remote environment and interact with your project services and modify settings.