How to Push Code to GitHub from VS Code to Add a New Project

To push code to GitHub from VS Code for a new project, initialize a local Git repository in the Source Control panel, commit your files, and click "Publish Branch" to automatically create a remote GitHub repository and push your initial commit.

VS Code provides built-in Git source control integration that eliminates the need for command-line configuration when publishing new projects. The editor's GUI handles repository initialization, staging, committing, and remote synchronization directly through the Source Control sidebar, streamlining the workflow for adding local projects to GitHub.

Initialize a Local Repository

Before pushing to GitHub, you must enable Git tracking in your workspace.

  1. Open your project folder in VS Code (File > Open Folder...).
  2. Click the Source Control icon (branch symbol) in the left Activity Bar, or press Ctrl+Shift+G (Cmd+Shift+G on macOS).
  3. Click the "Initialize Repository" button in the Source Control panel.

This creates a .git directory in your project root. The Source Control view will now display a "Changes" section listing all untracked files in your workspace.

Stage and Commit Initial Files

Prepare your project for its first upload by staging and committing files locally.

  • Stage changes: Hover over the "Changes" header and click the "+" (plus) icon to stage all files, or click the "+" next to individual files to select specific ones. Staged files move to the "Staged Changes" section.
  • Write a commit message: Enter a description (e.g., Initial commit) in the message input box at the top of the Source Control panel.
  • Commit: Press Ctrl+Enter (or click the checkmark icon) to create the commit on your local branch.

Your code is now tracked locally but has not yet been uploaded to GitHub.

Publish to GitHub (Add New Project)

To connect your local repository to a new GitHub project and push your code:

  1. In the Source Control panel, click "Publish Branch" (or open the ... More Actions menu and select Publish to GitHub).
  2. If prompted, click "Allow" to authorize VS Code to access your GitHub account. This opens a browser window to complete authentication.
  3. Choose "Publish to GitHub private repository" or "Publish to GitHub public repository" based on your visibility preference.
  4. Verify the branch name (typically main or master) in the input field.

VS Code executes the equivalent of git remote add origin and git push -u origin main automatically, creating the repository on GitHub and setting the upstream tracking reference.

Push Subsequent Changes

After the initial publish, pushing updates follows a simplified workflow:

  1. Commit locally: Stage your modified files and enter a commit message in the Source Control panel, then press Ctrl+Enter.
  2. Push to remote: Click the "Sync Changes" button (circular arrows icon) in the bottom Status Bar, or open the Command Palette (Ctrl+Shift+P) and run Git: Push.

This uploads your new commits to the existing GitHub repository without requiring additional authentication.

Summary

  • Initialize Git tracking via the Source Control panel to create a local .git repository.
  • Stage and commit files using the + icons and commit message box before attempting to push.
  • Publish Branch creates a new GitHub repository, sets the origin remote, and pushes the initial commit in a single step.
  • Sync Changes handles all subsequent pushes to upload local commits to the configured remote.

Frequently Asked Questions

How do I push code to GitHub from VS Code without using the terminal?

Use the Source Control sidebar for all operations. Click "Initialize Repository", then "Publish Branch" to create and connect to GitHub. For future updates, stage files, type a commit message, press Ctrl+Enter to commit, and click "Sync Changes" to push. This workflow requires no terminal commands.

Why does VS Code ask for GitHub authentication when I try to publish?

VS Code requests OAuth authentication to create repositories on your behalf and manage repository permissions securely. Click "Allow", sign in via the browser popup, and authorize the VS Code application. Credentials are stored in your operating system's keychain for seamless future pushes.

What is the difference between "Publish Branch" and "Push" in VS Code?

Publish Branch appears only when your local branch has no configured upstream remote (new projects). It creates the GitHub repository and establishes the connection. Push (or Sync Changes) appears after publishing and uploads new commits to the existing remote repository.

Can I change the repository visibility after publishing from VS Code?

Repository visibility (public/private) is selected during the initial publish action. To change it later, navigate to the repository's Settings on GitHub.com, scroll to the Danger Zone, and select "Change visibility". VS Code does not provide a UI for modifying visibility after the initial publish step.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s https://instagit.com/install.md

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client