Skip to main content

Creating a codespace for a repository

You can create a codespace for a branch in a repository to develop online.

Note

GitHub Codespaces is not available on subdomains of GHE.com, such as octocorp.ghe.com.

About creating a codespace for a repository

You can create a codespace on GitHub, in Visual Studio Code, or by using GitHub CLI. Use the tabs in this article to display instructions for each of these ways of creating a codespace.

You can use GitHub Codespaces on your personal GitHub account, with the quota of free use included each month for accounts on the Free and Pro plans. You can continue using GitHub Codespaces beyond your monthly included storage and compute usage by providing payment details and setting a spending limit. See About billing for GitHub Codespaces.

Organizations can enable members and outside collaborators to create and use codespaces at the organization's expense. For more information, see Choosing who owns and pays for codespaces in your organization.

Your ability to create codespaces from organization-owned repositories depends on several factors, including the repository's visibility and the settings of the organization or its parent enterprise. For more information, see Troubleshooting creation and deletion of codespaces.

Note

If you have a managed user account, you cannot create codespaces for your personal repositories, unless the repository is a fork of an organization-owned repository and you are allowed to use GitHub Codespaces at the organization's expense. For more information, see About Enterprise Managed Users.

If you're starting a new project, you might want to create a codespace from a template and publish to a repository on GitHub later. For more information, see Creating a codespace from a template.

If you create a codespace from a repository, the codespace will be associated with a specific branch, which cannot be empty. You can create more than one codespace per repository or even per branch.

You can see every available codespace that you have created on the "Your codespaces" page. To display this page, in the top-left corner of GitHub, select , then click Codespaces. This takes you to github.com/codespaces.

The codespace creation process

When you create a codespace, a number of steps happen to create and connect you to your development environment:

  • Step 1: VM and storage are assigned to your codespace.
  • Step 2: Container is created and your repository is cloned.
  • Step 3: You can connect to the codespace.
  • Step 4: Codespace continues with post-creation setup.

For more information on what happens when you create a codespace, see Deep dive into GitHub Codespaces.

For more information on the lifecycle of a codespace, see Understanding the codespace lifecycle.

If you want to use Git hooks for your codespace, then you should set up hooks using the devcontainer.json lifecycle scripts, such as postCreateCommand. These get executed during step 4, above. For information about the lifecycle scripts, see the dev containers specification on the Development Containers website. Since the dev container for your codespace is created after the repository is cloned, any git template directory configured in the dev container image will not apply to your codespace. Hooks must instead be installed after the codespace is created.

You can edit code, debug, and use Git commands while developing in a codespace with VS Code. For more information, see the VS Code documentation.

To speed up codespace creation, repository administrators can enable GitHub Codespaces prebuilds for a repository. For more information, see About GitHub Codespaces prebuilds.

Creating a codespace for a repository

After you connect your account on GitHub to the GitHub Codespaces extension, you can create a new codespace. For more information about the GitHub Codespaces extension, see the VS Code Marketplace.

  1. In VS Code, in the Activity Bar, click the Remote Explorer icon.

    Screenshot of the Activity Bar. The icon for the "Remote Explorer" side bar (a rectangle overlaid by a circle) is highlighted with an orange outline.

    Note

    If the Remote Explorer is not displayed in the Activity Bar:

    1. Access the Command Palette. For example, by pressing Shift+Command+P (Mac) / Ctrl+Shift+P (Windows/Linux).
    2. Type: details.
    3. Click Codespaces: Details.
  2. Hover over the "Remote Explorer" side bar and click .

    Screenshot of the "Remote Explorer" side bar for GitHub Codespaces. The tooltip "Create New Codespace" is displayed beside the plus sign button.

  3. In the text box, type the name of the repository you want to develop in, then select it.

    Screenshot of "octo-org/he" entered into the text box and a list of four repositories that start with this string.

    A message is displayed at the right side of subsequent prompts telling you who will pay for the codespace.

    Screenshot of a prompt for a branch, with the message "Usage paid for by hubwriter."

  4. Click the branch you want to develop on.

  5. If prompted to choose a dev container configuration file, choose a file from the list.

  6. Click the machine type you want to use.

    Note

    Your choice of available machine types may be limited by a number of factors. These can include a policy configured for your organization, or a minimum machine type specification for your repository. For more information, see Restricting access to machine types and Setting a minimum specification for codespace machines.

Further reading