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 In einem Codespace entwickeln.
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. Wenn du ein neues Projekt startest, kannst du einen Codespace über eine Vorlage erstellen und später in einem Repository in GitHub veröffentlichen. For more information, see Erstellen eines Codespaces für ein Repository and Erstellen eines Codespaces aus einer Vorlage.
Es gibt Grenzwerte für die Anzahl von Codespaces, die du erstellen kannst, sowie für die Anzahl der Codespaces, die du gleichzeitig ausführen kannst. Diese Grenzwerte variieren je nach Anzahl von Faktoren. Wenn du die maximale Anzahl von Codespaces erreichst und versuchst, andere zu erstellen, wird eine Meldung angezeigt, dass du einen vorhandenen Codespace entfernen musst, bevor du einen neuen erstellen kannst. 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.
Um die Erstellung von Codespaces zu beschleunigen, können Repositoryadministrator*innen GitHub Codespaces-Prebuilds für ein Repository aktivieren. Weitere Informationen finden Sie unter Weitere Informationen zu GitHub Codespaces-Prebuilds.
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 Verwenden der Quellcodeverwaltung in deinem 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 Festlegen des Timeoutzeitraums für 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
Wenn du den Container in einem Codespace neu erstellst, werden Änderungen, die du außerhalb des Verzeichnisses /workspaces
vorgenommen hast, gelöscht. Änderungen, die du innerhalb des Verzeichnisses /workspaces
vorgenommen hast, das den Klon des Repositorys oder der Vorlage enthält, aus dem du den Codespace erstellt hast, bleiben bei einer Neuerstellung erhalten. Weitere Informationen finden Sie unter Deep dive into GitHub Codespaces.
For more information, see Einführung in Entwicklungscontainer and Neuerstellen des Containers in einem Codespace.
Stopping a codespace
Codespaces können jederzeit beendet werden. Wenn Sie einen Codespace beenden, werden alle ausgeführten Prozesse beendet. Alle gespeicherten Änderungen in deinem Codespace sind weiterhin verfügbar, wenn du den Codespace beim nächsten Mal startest. Der Terminalverlauf wird beibehalten, aber der sichtbare Inhalt des Terminalfensters wird nicht zwischen Codespacesitzungen beibehalten.
Wenn du einen Codespace nicht explizit beendest, wird er weiterhin ausgeführt, bis aufgrund von Inaktivität ein Timeout auftritt. Das Schließen eines Codespaces beendet den Codespace nicht. Wenn du beispielsweise einen Codespace auf dem VS Code-Webclient verwendest und die Browserregisterkarte schließt, wird der Codespace weiterhin auf dem Remotecomputer ausgeführt. Weitere Informationen zu Timeouts findest du unter Understanding the codespace lifecycle.
Nur beim Ausführen von Codespaces fallen CPU-Gebühren an. Für einen beendeten Codespace fallen nur Speicherkosten an.
Es kann sinnvoll sein, einen Codespace zu beenden und neu zu starten, um Änderungen anzuwenden. Wenn du z. B. den für deinen Codespace verwendeten Computertyp änderst, musst du den Codespace beenden und neu starten, damit die Änderungen wirksam werden. Du kannst deinen Codespace auch beenden und ihn neu starten oder löschen, wenn ein Fehler oder ein unerwartetes Verhalten auftritt. For more information, see Beenden und Starten eines Codespaces.
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 Exportieren von Änderungen in einen Branch.
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 Konfigurieren des automatischen Löschens deiner 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 Informationen zur Abrechnung für 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 Anzeigen deiner GitHub Codespaces-Nutzung.
For more information on deleting a codespace, see Einen Codespace löschen.
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.