Push Commits to a Remote Repository in VS Code

This article explains how to push your local Git commits to a remote repository directly from Visual Studio Code. You will learn how to use the built-in Source Control interface, the Command Palette, and the integrated terminal to safely upload your code changes to platforms like GitHub, GitLab, or Bitbucket.

Method 1: Using the Source Control Interface

The easiest way to push commits in VS Code is through the graphical user interface.

  1. Open the Source Control view by clicking the branch icon in the Activity Bar on the left side of the window, or press Ctrl+Shift+G (Windows/Linux) or Cmd+Shift+G (macOS).
  2. Ensure you have committed your changes. If you have uncommitted changes, stage them, type a commit message, and click Commit.
  3. Once committed, you will see a Sync Changes button. Clicking this button will both pull new changes from the remote repository and push your local commits.
  4. Alternatively, click the Views and More Actions icon (the three dots ... at the top of the Source Control panel), hover over Push, and select Push to upload your commits without pulling first.

Method 2: Using the Command Palette

If you prefer using keyboard shortcuts without opening the side panel, you can use the Command Palette.

  1. Open the Command Palette by pressing Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS).
  2. Type Git: Push into the search bar.
  3. Select Git: Push from the dropdown menu to send your commits to the default remote branch. If you want to push to a specific remote or branch, select Git: Push To… instead.

Method 3: Using the Integrated Terminal

For developers who prefer the command line, VS Code features an integrated terminal.

  1. Open the terminal by pressing Ctrl+` (Windows/Linux) or Cmd+` (macOS), or select Terminal > New Terminal from the top menu.

  2. Verify you are on the correct branch by typing:

    git branch
  3. Push your commits to the remote repository using the standard Git command:

    git push origin <branch-name>

    Replace <branch-name> with the name of your active branch (for example, main or developer). If you are pushing a branch for the first time, use git push -u origin <branch-name> to set the upstream tracking branch.