Reference

How To

Step-by-step guides for common tasks you'll do as a developer.

How to Create a New Repository in GitHub and Push Your Code from VS Code

This guide walks you through creating a new repository on GitHub and pushing your local code to it using VS Code.

Before You Start

  • -You have a GitHub account
  • -VS Code is installed on your computer
  • -Git is installed (VS Code usually prompts you to install it)
  • -You have a project folder with code you want to push
1

Create a New Repository on GitHub

Go to github.com, sign in, and click the + icon in the top right corner. Select "New repository".

Click the plus icon and select New repository
2

Name Your Repository and Configure Settings

  • Enter a repository name (e.g., my-project)
  • Choose Private (or Public if you want others to see it)
  • Important: Do NOT check "Add a README file" since you already have code
Name your repository and set it to private without a README

Click "Create repository" when done.

3

Copy the Repository URL

After creating the repository, GitHub shows you setup instructions. Copy the repository URL (ends in .git).

Copy the repository git URL
4

Open Terminal in VS Code

In VS Code, right-click on your project folder in the sidebar and select "Open in Integrated Terminal".

Right-click folder and open in integrated terminal
5

Initialize Git

In the terminal, run:

git init
Run git init in terminal

This creates a new Git repository in your project folder.

6

Connect to GitHub

Run this command, replacing the URL with the one you copied in Step 3:

git remote add origin https://github.com/yourusername/your-repo.git
Run git remote add origin command

This tells Git where to push your code.

7

Stage Your Files

Click on the Source Control icon in the left sidebar (or press Ctrl+Shift+G). Click the + button next to "Changes" to stage all files.

Stage files for commit in VS Code
8

Write a Commit Message and Commit

Type a commit message (e.g., "Initial commit") in the message box at the top, then click the Commit button.

Add commit message and click commit
9

Push to GitHub

Click the three dots (...) menu in the Source Control panel and select Push, or click "Publish Branch" if you see that button.

Click three dots then push, or click publish branch

Done! Refresh your GitHub repository page to see your code.