Skip to main content

Understanding the codespace lifecycle

Learn how to develop in a GitHub Codespaces environment, and maintain your data throughout the entire codespace lifecycle.

Note

This article explains the stages in the life of a codespace, from creation to deletion. If you have read the Quickstart for GitHub Codespaces article and you now want to start using GitHub Codespaces for your own work, see the articles under Desarrollar en un codespace.

About the lifecycle of a codespace

The lifecycle of a codespace begins when you create a codespace and ends when you delete it. You can disconnect and reconnect to an active codespace without affecting its running processes. You may stop and restart a codespace without losing changes that you have made to your project.

Creating a codespace

When you want to work on a project, you can choose to create a new codespace or open an existing codespace. You might want to create a new codespace from a branch of your repository each time you develop in GitHub Codespaces or keep a long-running codespace for a feature. Si vas a iniciar un nuevo proyecto, es posible que desees crear un codespace a partir de una plantilla y publicar en un repositorio en GitHub más tarde. For more information, see Creación de un codespace para un repositorio and Creación de un codespace a partir de una plantilla.

Hay límites para el número de codespaces que puede crear y el número de codespaces que puede ejecutar al mismo tiempo. Estos límites varían en función de varios factores. Si alcanza el número máximo de codespaces e intenta crear otro, se muestra un mensaje que indica que debe quitar un codespace existente para poder crear uno nuevo. Similarly, if you reach the maximum number of active codespaces and you try to start another, you are prompted to stop one of your active codespaces.

If you choose to create a new codespace each time you work on a project, you should regularly push your changes so that any new commits are on GitHub. If you choose to use a long-running codespace for your project, you should pull from your repository's default branch each time you start working in your codespace so that your environment has the latest commits. This workflow is very similar to if you were working with a project on your local machine.

Para acelerar la creación de codespaces, los administradores de repositorios pueden habilitar precompilaciones de GitHub Codespaces para un repositorio. Para más información, consulta Acerca de las precompilaciones de GitHub Codespaces.

Saving changes in a codespace

When you connect to a codespace through the web, auto-save is enabled automatically for the web editor and configured to save changes after a delay. When you connect to a codespace through Visual Studio Code running on your desktop, you must enable auto-save. For more information, see Save/Auto Save in the Visual Studio Code documentation.

Your work will be saved on a virtual machine in the cloud. You can close and stop a codespace and return to the saved work later. If you have unsaved changes, your editor will prompt you to save them before exiting. However, if your codespace is deleted, then your work will be deleted too. To persist your work, you will need to commit your changes and push them to your remote repository, or publish your work to a new remote repository if you created your codespace from a template. For more information, see Utilizar el control de código fuente en tu codespace.

Timeouts for GitHub Codespaces

If you leave your codespace running without interaction, or if you exit your codespace without explicitly stopping it, the codespace will timeout after a period of inactivity and stop running. By default, a codespace will timeout after 30 minutes of inactivity, but you can customize the duration of the timeout period for new codespaces that you create. For more information about setting the default timeout period for your codespaces, see Configuración del periodo de tiempo de espera para GitHub Codespaces. For more information about stopping a codespace, see Stopping a codespace.

When a codespace times out, your data is preserved from the last time your changes were saved. For more information, see Saving changes in a codespace.

Rebuilding a codespace

You can rebuild your codespace to implement changes you've made to your dev container configuration. For most uses, you can create a new codespace as an alternative to rebuilding a codespace. By default, when you rebuild your codespace, GitHub Codespaces will reuse images from your cache to speed up the rebuild process. Alternatively, you can perform a full rebuild, which clears your cache and rebuilds the container with fresh images.

Note

Al recompilar el contenedor de un codespace, los cambios realizados fuera del directorio /workspaces se borran. Los cambios realizados dentro del directorio /workspaces, entre los que se incluye el clon del repositorio o la plantilla desde la que ha creado el codespace, se conservan al recompilar. Para más información, consulta Deep dive into GitHub Codespaces.

For more information, see Introducción a los contenedores dev and Recompilación del contenedor en un codespace.

Stopping a codespace

Puedes detener un codespace en cualquier momento. Cuando detiene un codespace, cualquier proceso en ejecución se detiene. Cualquier cambio que hayas guardado en tu codespace aún estará disponible cuando lo vuelvas a iniciar. El historial de terminales se conserva, pero el contenido visible de la ventana del terminal no se conserva entre las sesiones de codespace.

Si no detienes un codespace explícitamente, este seguirá ejecutándose hasta que se detenga por inactividad. El cierre de un codespace no detiene el codespace. Por ejemplo, si usas un codespace en el cliente web de VS Code y cierras la pestaña del explorador, el codespace continúa ejecutándose en la máquina remota. Para obtener información sobre el agotamiento del tiempo de espera, consulta Understanding the codespace lifecycle.

Solo los codespaces en ejecución incurren en cargos de CPU. Un espacio de código detenido solo conlleva costes de almacenamiento.

Es posible que debas detener y reiniciar un codespace para que se apliquen los cambios a este. Por ejemplo, si cambias el tipo de máquina que utilizas para tu codespace, necesitarás detenerlo y reiniciarlo para que el cambio tome efecto. También puedes detener tu codespace y elegir restablecerlo o borrarlo si encuentras un error o algo inesperado. For more information, see Detención e inicio de un codespace.

Deleting a codespace

You can create a codespace for a particular task and then safely delete the codespace after you push your changes to a remote branch.

If you try to delete a codespace with unpushed git commits, your editor will notify you that you have changes that have not been pushed to a remote branch. You can push any desired changes and then delete your codespace, or continue to delete your codespace and any uncommitted changes. You can also export your code to a new branch without creating a new codespace. For more information, see Exportar los cambios a una rama.

Codespaces that have been stopped and remain inactive for a specified period of time will be deleted automatically. By default, inactive codespaces are deleted after 30 days, but you can customize your codespace retention period. For more information, see Configuración de la eliminación automática de los codespaces.

If you create a codespace, it will continue to accrue storage charges until it is deleted, irrespective of whether it is active or stopped. For more information, see Acerca de la facturación de GitHub Codespaces. Deleting a codespace does not reduce the current billable amount for GitHub Codespaces, which accumulates during each monthly billing cycle. For more information, see Visualización del uso de GitHub Codespaces.

For more information on deleting a codespace, see Borrar un codespace.

Losing the connection while using GitHub Codespaces

GitHub Codespaces is a cloud-based development environment and requires an internet connection. If you lose connection to the internet while working in a codespace, you will not be able to access your codespace. However, any uncommitted changes will be saved. When you have access to an internet connection again, you can connect to your codespace in the exact same state that it was left in. If you have an unstable internet connection, you should commit and push your changes often.

If you know that you will often be working offline, you can use your devcontainer.json file with the "Dev Containers" extension for VS Code to build and attach to a local development container for your repository. For more information, see Developing inside a container in the Visual Studio Code documentation.