End to End Developer Experience with GitHub Codespaces
Tags: github, git, vscode
Published: 2020-12-10 11:36:37

Before we jump into this post, GitHub Universe 2020 had a lot of exciting content and if you need an updated end to end course on GitHub, check out: [Build community-driven software projects on GitHub](https://docs.microsoft.com/learn/paths/build-community-driven-projects-github/?WT.mc_id=startup-9868-chnwamba)

----------

Imagine having to not worry about which device you made the latest change on your project from. Imagine forgetting to push to GitHub from your laptop and still be able to continue coding on the go using your Surface Go or iPad. Picture a world where you have absolute freedom on the device you code with. 

![](https://paper-attachments.dropbox.com/s_C3E544DBEF597900175E27F0B11DE9ADA9ED3C12FDDFA23DDF56884776087022_1602488377703_image.png)


You must have heard of [Codespaces](https://github.com/features/codespaces) and how it enables you to write code from your browser or VS Code while persisting your changes in the cloud. What you probably haven’t had the time to do is have a first-hand experience of what Codespaces feels like and how it can be beneficial to you. The reason I wrote this article is to give you a feel of Codespace.


## Setting up Codespaces

Before you can create a Codespace, you need to set up the following:


1. A repository
2. At least a file in the repository

**Codespaces Requirements**

Let’s get these requirements out of the way by creating a basic node project and committing it to a repository

```bash
# Create a project directory
mkdir oauth-with-github && cd oauth-with-github

# Add a server and .gitignore files
echo "console.log('Welcome to Codespaces')" >> server.js
echo "node_modules" >> .gitignore

# Add a package.json file
npm init -y

# Install nodemon for watching
npm install -D nodemon
```

Add a `dev` script in the `package.json` file which you can use to trigger a nodemon command to start and watch the server:

```json
# ./package.json
"scripts": {
    "dev": "nodemon server.js"
}
```

[Create an empty repository](https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/create-a-repo) without a readme or any other file in it and push the new project you’ve just created:

```bash
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin <REPO URL>
git push origin main

# Feel free to delete the project locally
# 1. You don't need it anymore since you will be cloud-coding
# 2. You safe your future self the confusion of having 2 copies
cd ../
rm -rf oauth-with-github
```

**Open Repository with Codespaces**

Once you’ve got your project on GitHub, you can click the **Clone or download** button to open the project in Codespaces.

![](https://paper-attachments.dropbox.com/s_C3E544DBEF597900175E27F0B11DE9ADA9ED3C12FDDFA23DDF56884776087022_1602492248646_image.png)


Click **Open with Codespaces** from the dropdown menu to reveal all Codespaces that you have created for this repository. Since you have not created any, it will be empty with a button to create a new one.

![](https://paper-attachments.dropbox.com/s_C3E544DBEF597900175E27F0B11DE9ADA9ED3C12FDDFA23DDF56884776087022_1602492324662_image.png)


Click the **+ New codespace** button and wait for GitHub to initialize the Codespace for you

![](https://paper-attachments.dropbox.com/s_C3E544DBEF597900175E27F0B11DE9ADA9ED3C12FDDFA23DDF56884776087022_1602492500571_image.png)


Once that is done, you will be presented with a very familiar look — VS Code:

![](https://paper-attachments.dropbox.com/s_C3E544DBEF597900175E27F0B11DE9ADA9ED3C12FDDFA23DDF56884776087022_1602492530212_image.png)

## Connecting to Codespaces from Local VS Code

It still doesn’t feel right for you to code directly from the browser — I get it. I understand you don’t have time to [personalize the browser-based VS Code](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/personalizing-codespaces-for-your-account) to match your current local settings. “It’s not even in dark theme”, I hear you. 

To get you up to spead, what we can do is SSH into your Codespaces from VS Code and everybody wins:


1. Your code is in the cloud so it’s device-independent
2. You use your favorite editor with your favorite them and config
3. You have access to the remote terminal so you can still run all your shell commands

To connect to your Codespace from VS Code you need to complete 2 steps:


1. Connecting the Visual Studio Codespaces extension to your GitHub account
2. Open a Codespace from VS Code.

The complete the first step, follow [these setup steps](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/using-codespaces-in-visual-studio-code#connecting-the-visual-studio-codespaces-extension-to-your-github-account) to install the Codespaces VS Code extension and authorize it to have access to your GitHub account.

Once you have Codesapces extension installed and authorized, we can move on to the second step. Open the **Remote Explore** sidebar menu from the VS Code Sidebar and you should find all your Codespaces (I have 2).

![](https://paper-attachments.dropbox.com/s_C3E544DBEF597900175E27F0B11DE9ADA9ED3C12FDDFA23DDF56884776087022_1602500318289_image.png)


Click the **Connect to Codespace** icon that appears when you hover over a Codespace to connect to that particular Codespace.

![](https://paper-attachments.dropbox.com/s_C3E544DBEF597900175E27F0B11DE9ADA9ED3C12FDDFA23DDF56884776087022_1602500663717_image.png)


Few seconds after connecting, you should have your Codespace open in VS Code. From the screenshot below, you can see that my theme and VS Config is just how I like it

![](https://paper-attachments.dropbox.com/s_C3E544DBEF597900175E27F0B11DE9ADA9ED3C12FDDFA23DDF56884776087022_1602500897181_image.png)


You can differentiate a Codespace from a local project by the Codespace name on the bottom left of VS Code.

One last cool thing to mention is that you can choose to push changes to GitHub or not. You can learn more on [how to do this from VS Code](https://docs.microsoft.com/en-us/learn/modules/introduction-to-github-visual-studio-code/?WT.mc_id=startup-9868-chnwamba).