How to push code from VS Code to GitHub

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Pushing code from Visual Studio Code (VS Code) to GitHub involves several steps that ensure your code is safely uploaded to your GitHub repository. This guide provides detailed instructions on how to push code directly from VS Code to GitHub, utilizing both the graphical user interface (GUI) of VS Code and the integrated terminal.

  1. Create a new repository on GitHub:

    • Visit GitHub and sign in.
    • Click on the "New" button under the "Repositories" tab.
    • Enter your repository details and create the repository.
  2. Connect your local repository to your GitHub repository:

    • Open your terminal or command prompt.
    • Navigate to your project directory:
      Terminal
      cd path/to/your/project
    • Add the remote repository:
      Terminal
      git remote add origin https://github.com/username/repository.git
    • Verify the remote repository:
      Terminal
      git remote -v
  1. Open your project in VS Code.
  2. Open the Source Control panel:
    • Click on the Source Control icon on the sidebar or press Ctrl+Shift+G.
  3. Stage your changes:
    • Click on the '+' icon next to each changed file to stage files individually, or click on the "Stage All Changes" icon at the top to stage all changes.
  4. Commit your changes:
    • Enter a commit message in the input box at the top of the Source Control panel.
    • Press Ctrl+Enter to commit the staged files.
  5. Push your changes:
    • Click on the '...' button at the top of the Source Control panel, then select "Push" from the dropdown menu.
    • If you are pushing to a new branch, select "Push to" and enter the branch name.
  1. Open the integrated terminal in VS Code:
    • Use the shortcut Ctrl+` (Control + backtick) or navigate through View -> Terminal.
  2. Stage your changes:
    • Run the command:
      Terminal
      git add .
  3. Commit your changes:
    • Run the command:
      Terminal
      git commit -m "Your descriptive commit message"
  4. Push your changes:
    • To push to the main branch, run:
      Terminal
      git push origin main
    • To push to another branch, replace main with your branch name.
  • Check your current branch:
    • Before pushing, ensure you are on the correct branch using:
      Terminal
      git branch
  • Resolve conflicts:
    • If there are conflicts between your local and remote repositories, VS Code will alert you to resolve them before you can successfully push. For more information see this guide on resolving merge conflicts in Git.
  • Pull before you push:
    • It's a good practice to pull the latest changes from your remote repository to your local repository before pushing new changes:
      Terminal
      git pull origin main

For more information see the official VS Code documentation.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2