Merge and delete an environment (tutorial)

Merge an environment

This tutorial shows how to merge changes from an environment to its parent, which in this case is the master branch. You can, for example, merge code updates, new components, changes to themes, and so on.

You can then optionally delete the environment.

This tutorial shows how to create a sample file and merge it. This tutorial assumes you’re already working in an environment; if not, see Get started with an environment to create one.

You cannot merge environment variables because they are not code. You must set the value of environment variables in an environment.

Get started

To get started:

  1. Log in to your local development machine, or switch to, the Magento file system owner.
  2. Change to a directory to which the Magento file system owner has write access, such as the web server docroot.
  3. Log in to your project:

    magento-cloud login
    
  4. List your projects:

    magento-cloud project:list
    
  5. If necessary, clone a project.

    magento-cloud project:get <project ID>
    

    Typically, you should clone the project in the web server’s docroot or a Virtual Host docroot.

  6. Change to a project directory.

    For example, cd /var/www/html/magento2

  7. List environments in the project:

    magento-cloud environment:list
    

    magento-cloud environment:list displays environment hierarchies whereas git branch displays does not. If you have any nested environments, use magento-cloud environment:list.

  8. Fetch origin branches:

    git fetch origin
    
  9. Check out an environment:

    magento-cloud environment:checkout <environment ID>
    

    To create a new environment, use magento-cloud environment:branch <environment name> <parent environment ID>

  10. Pull updated code:

    git pull origin <environment ID>
    
  11. Create a snapshot of the environment.

    magento-cloud snapshot:create -e <environment ID>
    

Merge an environment

To merge an environment:

  1. Add a file named test.txt to the environment root directory.

    You can put whatever contents you want; for example, the number 1

  2. Save your changes and exit the text editor.
  3. Add, commit, and push your change to the environment:

    git add -A
    git commit -m "<commit message>"
    git push origin <branch name>
    

    Where <branch name> is the Git name of the environment (that is, the environment ID).

  4. Merge with the parent environment:

    magento-cloud environment:merge <environment ID>
    

    For example,

    magento-cloud environment:merge master
    

Optionally delete the environment

Before you delete an environment, make sure you don’t need it anymore. You cannot recover a deleted environment later.

You cannot delete the master environment of any project.

You must be a project administrator, environment administrator, or account owner to perform this task.

This section discusses how to optionally delete an environment in the following ways:

  • Make the environment inactive but let it remain in the project
  • Delete the environment entirely and remove it from the project

To delete a environment:

  1. Log in to your project if you haven’t already done so.
  2. Fetch branches from the origin server.

    git fetch origin
    
  3. To delete the branch entirely (removing it from the project), check out the branch.

    magento-cloud environment:checkout <environment ID>
    
  4. Delete the environment:

    magento-cloud environment:delete <environment ID>
    

    For example, to delete the deleteme environment:

    magento-cloud environment:delete deleteme
    

    To delete more than one environment:

    magento-cloud environment:delete <environment ID> <environmentID>
    

    For additional options, see the command-line help:

    magento-cloud environment:delete --help
    
  5. Answer the prompt:

    Are you sure you want to delete the remote Git branch deleteme? [Y/n]
    

    A Y answer makes the branch inactive but leaves it in the project.

  6. Answer the prompt:

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

    A Y answer completely removes the branch from the project.

Wait for the environment to delete.

To activate the environment later, use the magento-cloud environment:activate command.

Set Magento environment variables