Lesson - Publish your repository

As a Visual Studio Code user who has authenticated to GitHub, you'll get some improvements to your GitHub workflow. One of those improvements is the ability to publish a project from your machine directly to GitHub.

What is publishing?

If you're starting with a new project that you haven't yet pushed to GitHub, the process for getting it up on GitHub has quite a few steps:

  1. Create a GitHub repo on Github.com.
  2. Copy the remote endpoint.
  3. Run git init locally.
  4. Add the remote endpoint.
  5. Specify which items to push into GitHub with a .gitignore file.
  6. Stage files.
  7. Add a commit message.
  8. Push to the repo.

A lot of steps means a lot of work.

Visual Studio Code has a built-in publishing feature that fully automates this process and allows you to do it right from its interface.

Publishing to GitHub from Visual Studio Code

There are two ways to publish a project to GitHub from Visual Studio Code: from the Source Control Management (SCM) view and from the Command Palette. You must have a folder open in Visual Studio Code to see these options.

Tip

You can always use Git from the built-in terminal in Visual Studio Code as well (Ctrl + `). Just because you're using visual source control tools in Visual Studio Code doesn't mean that you have to completely forgo your beloved command line!

Publishing from the SCM View

If you haven't already started a repository for your project, you can publish your project directly from the SCM view.

You can toggle the SCM view in Visual Studio Code by selecting the SCM icon on the Activity Bar. You'll see a button that says Publish to GitHub.

Screenshot that shows the Source Control Management view in Visual Studio Code, with the Publish to GitHub button outlined.

Selecting this button will start the publishing process:

  1. Specify the name of the repository to create on GitHub.
  2. Specify which files should be pushed to GitHub. Any files that you don't select are automatically added to a .gitignore file, which is created during the publishing process.
  3. Your code is staged and committed with the message "first commit."
  4. Your code is pushed to the newly created GitHub repo.

Publishing from the Command Palette

If your project has already been started for GitHub locally, you won't see the publish button in the SCM view. You can still publish your project to GitHub by using the Publish to GitHub option on the Command Palette.

Screenshot of the Visual Studio Code Command Palette, showing the Publish to GitHub option.

The action kicks off the same workflow that the publish button in the SCM view does, and it has exactly the same steps. You won't be prompted for what items you want to push if your project already contains a .gitignore file.