GitHub Codespaces
GitHub Codespaces is a cloud-based development environment that allows you to develop directly within GitHub. It is a browser-based version of Visual Studio Code with a file manager, editor, and shell to enter commands. All GitHub Classroom projects, exercises, and examples in this class have GitHub Codespaces available, and any cost is charged to the organization, not the student.
To create a GitHub Codespace:
- Go to your GitHub Classroom repository on GitHub
- Select the Code button
- Select the Codespaces tab
- Press the Create codespace on main
This will start the codespace in your browser. The codespace automatically:
- Authenticates you to GitHub (the equivalent of the
gh auth
process)
- Clones your repository (equivalent to the
git clone ...
)
- Moves you into the repository directory (equivalent to the
cd ...
)
At this point, you can enter git
commands in the shell.
Local Visual Studio Code
If you want, you can connect a locally-run Visual Studio Code to an existing codespace.
- Install the GitHub Codespace Extension
- Start a codespaces on the web
- Go back to the GitHub repository page where you created the codespace
- Under the
...
select the option Open in Visual Studio Code
At this point, you can close the browser codespace instance and work locally in that codespace.
Internals
- The codespaces are run as a docker container. The container docker image is based on a Linux distribution, typically Ubuntu or Debian.
- There are default images for different types of development.
- You can customize the image via the file .devcontainer.json. This image can add packages, install other software, and allow more permissions. Most of the assignments will use custom images.
- If the image is updated, you must close the current codespace, delete it, and create another one. I will post when this is necessary.
- If you have Docker installed, you can locally run the same image as the one running in codespaces. However, it won't be automatically authenticated with GitHub, your repository won't be cloned, and you will not be placed into the proper directory.
- All of my Docker images are multi-platform and can run natively on both x86 (Windows, WSL) and ARM (MacOS) platforms.