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:
- Log in to your local development system, or switch to, the Magento file system owner.
- Change to a directory to which the Magento file system owner has write access.
-
Enter the following command in a terminal to log in to your project:
1
magento-cloud login
-
List your projects. With the project ID, you can complete additional commands.
1
magento-cloud project:list
-
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>
- Change to a project directory. For example,
cd /var/www/html/magento2
-
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 thegit branch
command does not. -
Fetch origin branches to get the latest code:
1
git fetch origin
-
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>
-
Pull any updated code to your local for the environment ID (which is the Git branch):
1
git pull origin <environment ID>
-
Create a snapshot of the environment as a backup:
1
magento-cloud snapshot:create -e <environment ID>
Merge an environment
To merge an environment:
-
Add a file named
test.txt
to the environment root directory.You can put whatever contents you want; for example, the number
1
- Save your changes and exit the text editor.
-
Add, commit, and push your change to the environment:
1
git add -A
1
git commit -m "<commit message>"
1
git push origin <branch name>
Where
<branch name>
is the Git name of the environment (that is, the environment ID). -
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:
- Log in to your project if you haven’t already done so.
-
Fetch branches from the origin server.
1
git fetch origin
-
To delete the branch entirely (removing it from the project), check out the branch.
1
magento-cloud environment:checkout <environment ID>
-
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
-
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. -
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.