Getting Started with GitHub Codespaces

By Łukasz Kallas
Picture of the author
Published on
programming image

GitHub Codespaces is a cloud-powered development environment that allows you to code directly in your browser. With pre-configured dev environments, you can start coding in seconds without worrying about setting up your machine. In this post, we'll walk you through setting up your first Codespace and show you the flexibility it offers.

Why Use GitHub Codespaces?

  • Instant Environment Setup: No need to manually set up dependencies or tooling. Start coding right away.
  • Portability: Your environment is stored in the cloud, meaning you can switch between devices effortlessly.
  • Integrated with GitHub: Seamless integration with your GitHub repositories.

Hands-On: Setting Up GitHub Codespaces

Step 1: Enabling Codespaces
  1. Go to your repository on GitHub.
  2. Click the Code button and then select Open with Codespaces.
  3. If it's your first time, GitHub may ask you to enable Codespaces.
Step 2: Creating a New Codespace
  1. Once enabled, click Create New Codespace on Main. This will set up a development environment in a few seconds.
  2. Once the environment is ready, you'll see the familiar Visual Studio Code interface in your browser.
Step 3: Exploring Codespace Features
  • Pre-configured Dev Containers: These are Docker-based environments that come with all dependencies needed for your project.
  • Port Forwarding: You can run and preview applications inside Codespaces using port forwarding.
  • Extensions: Install VS Code extensions as you normally would on your local machine.
Step 4: Customizing Your Codespace

You can customize the dev environment by adding a .devcontainer directory in your repository, which includes configuration files for the container.

Here’s an example of a devcontainer.json file:

{
  "name": "Node.js Codespace",
  "image": "mcr.microsoft.com/vscode/devcontainers/javascript-node:0-14",
  "extensions": ["dbaeumer.vscode-eslint"],
  "postCreateCommand": "npm install"
}

Stay Tuned

Want to learn?
The best articles, links and news related to software development delivered once a week to your inbox.