Skip to main content

Создание пространства кода на основе шаблона

If you're starting a new project, you can get started with development work quickly by creating a codespace from a template. You'll be able to work on your project in a cloud-based development environment, save your files in the cloud, and publish your work to a new remote repository that you can share with others or clone to your local machine.

You can start from a blank template, choose from templates maintained by for popular technologies such as React or Jupyter Notebook, or launch a codespace from any template repository on .

With a blank template, you'll start with an empty directory, with access to cloud-based compute resources and the tools, languages, and runtime environments that come preinstalled with the default dev container image. With other templates, you'll get starter files for the technology you're working with, plus typically some extra files such as a README file, a .gitignore file, and dev container configuration files containing some custom environment configuration. For more information on dev containers and the default image, see Introduction to dev containers.

As an example, if you create a codespace from 's React template, you'll arrive in a workspace containing template files for a simple application, such as index.js, app.js, and package.json. Shortly after the codespace opens, a development server will start up automatically, and you will be able to view the running application in a simple browser tab within the VS Code web client.

Screenshot of VS Code's simple browser rendering the web application in GitHub's React template.

The files and configuration included in templates are defined in template repositories. The template repository is cloned into your codespace when you create the codespace. After that, the link is severed, and your codespace won't be linked to a remote repository until you publish to one.

Совет

To help people get started with your framework, library, or other project, you can set up a template repository for use with Codespaces. For more information, see Setting up a template repository for Codespaces.

Templates maintained by , including the blank template, are available from the "Your codespaces" page.

  1. In the top-left corner of , select , then click Codespaces to take you to the "Your codespaces" page at .com/codespaces.

  2. To view the full list of templates, in the "Explore quick start templates" section, click See all.

    Screenshot of the "Explore quick start templates" section. "See all" is highlighted with a dark orange outline.

  3. Optionally, to view the template repository containing the files for a template, click the name of the template.

    Screenshot of the "Explore quick start templates" section. Three templates are listed. The templates names are outlined in orange.

  4. Under the name of the template you want to launch, click Use this template.

When you create a new codespace from a template, it is always opened in the Visual Studio Code web client. You can reopen an existing codespace in any supported editor. For more information, see Opening an existing codespace.

You can create a codespace from any template repository, then publish your work to a new repository when you are ready. For more information on template repositories, see Creating a repository from a template.

  1. On , navigate to the main page of the repository.

  2. Click Use this template, then click Open in a codespace.

    Screenshot of the "Use this template" button and the dropdown menu expanded to show the "Open in a codespace" option.

    Примечание.

    If you're a maintainer of the template repository, and want to commit changes to the template repository itself, you should create a codespace from the Code dropdown. For more information, see Creating a codespace for a repository.

When you create a new codespace from a template, it is always opened in the Visual Studio Code web client. You can reopen an existing codespace in any supported editor. For more information, see Opening an existing codespace.

When you work in a codespace created from a template, your work is saved on a virtual machine in the cloud, but it is not stored in a repository on .

You can save your files, close and stop your codespace, and come back to your work later. Typically, Git will come preinstalled, and the working directory will be automatically initialized as a Git repository unless you started from 's blank template. This means you can immediately use Git for local source control, such as adding and committing files.

However, if you delete an unpublished codespace, or if it's automatically deleted by being left unused for the duration of the retention period, then your work will be deleted too. To persist your work, and to allow others to work on your project, you will need to publish your codespace to a repository on .

Примечание.

If an unpublished codespace is currently billed to an organization, publishing the codespace transfers ownership and billing of the codespace to your personal account. See About billing for Codespaces.

If you're working in a codespace, you can publish it from the VS Code web client or desktop application.

  1. In the Activity Bar, click the Source Control view.

    Screenshot of the VS Code Activity Bar with the source control button highlighted with an orange outline.

  2. To stage your changes, click + next to the file you've added or changed, or next to Changes if you've changed multiple files and you want to stage them all.

    Screenshot of the "Source control" side bar with the staging button (a plus sign), to the right of "Changes," highlighted with a dark orange outline.

    Примечание.

    If you start from 's blank template, you will not see a list of changes unless you have already initialized your directory as a Git repository. To publish codespaces created from the blank template, click Publish to in the "Source Control" view, then skip to step 5.

  3. To commit your staged changes, type a commit message describing the change you've made, then click Commit.

    Screenshot of the "Source control" side bar with a commit message and, below it, the "Commit" button both highlighted with a dark orange outline.

  4. Click Publish Branch.

    Screenshot of the "Source control" side bar showing the "Publish Branch" button.

  5. In the "Repository Name" dropdown, type a name for your new repository, then select Publish to private repository or Publish to public repository.

    Screenshot of the repository name dropdown in VS Code. Two options are shown, for publishing to a private or a public repository.

    The owner of the new repository will be the account with which you created the codespace.

  6. Optionally, in the pop-up that appears in the lower right corner of the editor, click Open on to view the new repository on .

    Screenshot of a confirmation message for a successfully published repository, showing the "Open on GitHub" button.

When a codespace is published, you have access to a greater range of options to customize your Codespaces experience. For example, you can:

You can publish an unpublished codespace from the "Your codespaces" page on . This is useful if you want to publish a codespace that you don't currently have open in your browser. If you do this, your work will be preserved in a repository, but there won't be a link between your existing codespace and the new repository. However, you can navigate to the new repository and create a codespace from there, and this codespace will be connected to the repository.

  1. In the top-left corner of , select , then click Codespaces to take you to the "Your codespaces" page at .com/codespaces.

  2. Next to the unpublished codespace, click the ellipsis (...), then select Publish to a new repository.

    Screenshot of the dropdown menu for a codespace, showing the "Publish to a new repository" option.

  3. Choose a name for your new repository, set it as Public or Private, and click Create repository.

    Screenshot of the "Publish to a new repository" dropdown, with the "Name" field, "Public" and "Private" options, and "Create repository" button.

  4. Optionally, to view the new repository, click See repository.