Manage branches with the CLI

Last update: 2024-02-05
  • Topics:
  • Cloud
    View more on this topic
  • Install
    View more on this topic
  • Created for:
  • Developer

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.

IMPORTANT

Some Git commands cannot complete an action in your Adobe Commerce on cloud infrastructure project. For example, you can create a branch using a Git command, but you cannot create and activate a new environment. You must create an environment using the 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:

  1. Log in to your local workstation with a file system owner account.

  2. Change to the web server or virtual host docroot directory.

  3. Log in using the magento-cloud CLI.

    magento-cloud login
    
  4. List your projects.

    magento-cloud project:list
    
  5. Clone a project.

    magento-cloud project:get <project-ID>
    

    When prompted, provide a directory name.

  6. Change to the magento2 directory.

  7. List available environments for the project.

    magento-cloud environment:list
    
    IMPORTANT

    The magento-cloud environment:list command displays environment hierarchies, whereas the git branch command does not.

  8. Fetch the remote branches.

    git fetch origin
    
  9. Pull updated code.

    git pull origin <environment-ID>
    
TIP

See Integrations for information about using Git-based hosting services with Adobe Commerce on cloud infrastructure.

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.

  • For Starter, consider creating a branch for staging, then create a development branch based on the staging branch.
  • For Pro, create development branches based on the Integration branch.

To create a development branch:

  1. On your local workstation, change to your project directory.

  2. Create an environment based on the branch recommended for your project workflow.

    magento-cloud branch <new-environment-name> integration
    
  3. Update dependencies.

    composer --no-ansi --no-interaction install --no-progress --prefer-dist --optimize-autoloader
    
  4. [optional] Create a backup of the environment.

Merge a branch

After completing development, merge this branch to the parent:

  1. Commit and push code changes:

    git add -A && git commit -m "Add message here"
    
    git push origin <branch-name>
    
  2. Merge with the parent environment:

    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.

WARNING

You cannot delete the 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:

  1. On your local workstation, change to your project directory.

  2. Fetch updates from the remote server.

    git fetch
    
  3. Delete the environment branch.

    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.

    magento-cloud environment:delete <environment-1-ID> <environment-2-ID>
    
  4. Respond to the prompts to delete the local environment and the corresponding remote environment.

    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.

    Delete the remote Git branch too? [Y/n]
    

    Deleting the remote Git branch removes the environment from the project.

  5. Wait for the environment to delete.

    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.
    
TIP

To activate an inactive environment, use the 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.

On this page