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 system, or switch to, the Magento file system owner.
  2. Change to a directory to which the Magento file system owner has write access.
  3. Enter the following command in a terminal to log in to your project:

    1
    
    magento-cloud login
    
  4. List your projects. With the project ID, you can complete additional commands.

    1
    
    magento-cloud project:list
    
  5. If necessary, clone the project to your local. You should have cloned when setting up your local development workspace.

    1
    
    magento-cloud project:get <project ID>
    
  6. Change to a project directory. For example, cd /var/www/html/magento2
  7. List environments in the project. Every environment includes an active Git branch of your code, database, environment variables, configurations, and services.

    1
    
    magento-cloud environment:list
    
    magento-cloud environment:list—displays environment hierarchies whereas the git branch command does not.
  8. Fetch origin branches to get the latest code:

    1
    
    git fetch origin
    
  9. Check out, or switch to, a specific branch and environment. Git commands only checkout the Git branch. The Magento Cloud command also switches to the active environment.

    1
    
    magento-cloud environment:checkout <environment ID>
    

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

  10. Pull any updated code to your local for the environment ID (which is the Git branch):

    1
    
    git pull origin <environment ID>
    
  11. Create a snapshot of the environment as a backup:

    1
    
    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:

    1
    2
    3
    
    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:

    1
    
    magento-cloud environment:merge <environment ID>
    

    For example,

    1
    
    magento-cloud environment:merge master
    

Optionally delete the environment

You need to verify that you do not need an environment before you delete it. 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.

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

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

    1
    
    magento-cloud environment:delete <environment ID>
    

    For example, to delete the deleteme environment:

    1
    
    magento-cloud environment:delete deleteme
    

    To delete more than one environment:

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

    For additional options, see the command-line help:

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

    1
    
    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:

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