A codespace is a development environment hosted in the cloud, defined by configuration files in your repository. This creates a repeatable development environment tailored specifically to the project that simplifies developer onboarding and avoids the famous phrase "It works on my machine!" 😎
Each codespace follows the Dev Container specification and is hosted by GitHub as a Docker container.
But don't worry! You don't need to know Docker or even have it installed on your machine!
Tip
Since the Dev Container configuration is part of the repository, you can also use it locally with your own Docker host. Nice!
A Codespace has several advantages/features compared to local development. To name a few:
- Start a codespace directly from the repository page.
- Develop in the browser. No IDE installation required.
- Option to use a local install of VS Code to link to the remote Codespace.
- Preconfigure everything you need to run the project:
- Add features to install common development needs.
- Run scripts at various steps of the codespace lifecycle (e.g install python/npm packages).
- Setup VS Code settings and extensions to match the project needs.
- Fast internet access (since the container is in the datacenter).
Tip
Codespaces are even useful in short-lived situations like reviewing a pull request. No need to verify you have the right setup to test out the incoming code changes.
Let's get started! We'll start up a Codespace, run the application, make a change, and push it. Like normal development! 🤓
-
Open a second tab and navigate to this repository. Ensure you are on the Code tab.
-
Above the files list on the right, click the green <> Code button.
-
Select the Codespaces tab and click the Create codespace on main button. A new window will open running VS Code and it will connect to the remote Codespace. Wait a few minutes for the codespace to be created.
-
Look in the bottom left of the VS Code window see the remote connection.
Tip
GitHub uses the universal Codespace image if the repository doesn't include a configuration. It includes several useful and commonly used tools.
-
Ensure you are in the VS Code Codespace.
-
In the left sidebar, select the file Explorer tab and open the file
src/hello.py. -
In the lower panel, select the TERMINAL tab.
-
Paste the following command in the Codespace's remote terminal to show the installed versions of several tools. Note the versions for comparison later.
node --version dotnet --version python --version gh --version
-
Paste the following command to run the Python program in the Codespace's remote terminal.
python src/hello.py
-
Replace the
src/hello.pyfile contents with the following and save the file.print("Hello World!")
-
With the message updated, commit the change and push it to GitHub. Use VS Code's source control tools or the below terminal commands.
git add 'src/hello.py' git commit -m 'fix: incomplete hello message' git push
-
(optional) Back in your web browser, open the
src/hello.pyfile to to verify the change was updated. -
With the the change pushed to GitHub, Mona will begin checking your work. Give her a moment to provide feedback and the next learning steps.