Getting Set Up

Install Git and create a GitHub account

Git and GitHub are not the same thing, and mixing them up is where a lot of the confusion starts. Git is a program that runs on your own computer and keeps track of every version of your files. GitHub is a website that stores a copy of that history online, so you have a backup and a way to share your code. You need both: Git to create the history, GitHub to store and share it.

After installing Git, close and reopen VS Code so it picks up the new installation. VS Code checks for Git when it starts, not continuously.

Step by Step · Do This Once Per Computer

Set up VS Code to use your GitHub account

This is the step that confuses people the most, mostly because nothing on screen tells you to do it in advance, it just pops up the first time you need it. Follow this exactly once per computer, and you won't see it again.

  1. Open VS Code. Open any folder you'd like to turn into a project, using File → Open Folder. (If you're cloning a project that already exists on GitHub instead, skip ahead to the "Starting from the GitHub website" steps below, then come back here, since cloning is what triggers the sign-in prompt.)
  2. Click the Source Control icon in the thin strip of icons on the far left edge of the window. It looks like three dots connected by branching lines. You can also press Ctrl+Shift+G.
  3. If the folder is not already a Git project, you'll see one button: Initialize Repository. Click it. (This runs the git init command for you — explained in detail further down this page.)
  4. Make a small change to any file, then type a short message in the box at the top of the Source Control panel and click the checkmark icon to commit it. (If this step feels unfamiliar, read "Push a commit from VS Code" below first, then come back.)
  5. Click Publish Branch. This is the moment VS Code actually needs to know who you are, and a small window pops up in the bottom right corner of the screen asking you to sign in.
  6. Click Allow on that pop-up, then click Sign in with GitHub on the next one.
  7. Your default web browser opens automatically to a GitHub page. Log in to GitHub if you aren't already, then click the green Authorize Visual Studio Code button.
  8. Close the browser tab and switch back to VS Code. You should see a small confirmation message appear, and from now on your GitHub username shows up when you click the circular Accounts icon in the very bottom left corner of the window.

How to know it worked: click the Accounts icon in the bottom left corner of VS Code. If you see your GitHub username and avatar listed there, you're signed in and this entire section is done, permanently, on this computer.

Signing in only proves who you are. It does not give you write access to someone else's repository. To contribute to a repo you don't own, fork it first, push to your fork, then open a pull request.

Two Starting Points

Creating a repository: the GitHub website vs. VS Code

There are two completely normal ways to get a project onto GitHub, and which one you reach for depends on where your files already are. Both end up in the exact same place: a repository on GitHub, and a copy on your computer that's connected to it.

Option A: Start on the GitHub website

Use this when the project doesn't exist as files on your computer yet, or when you want GitHub to set up a README, a .gitignore, or a license for you before you write a single line of code.

  1. Go to github.com/new (or click the + icon in the top right of any GitHub page, then New repository).
  2. Type a repository name. Choose Public (anyone can see it) or Private (only you, and people you invite, can see it).
  3. Check Add a README file if this is a brand new project — it gives the repository its first file, so it isn't empty.
  4. Click the green Create repository button. GitHub now has your repository, with nothing on your computer yet.
  5. On the repository's page, click the green Code button, make sure HTTPS is selected (not SSH), and copy the URL shown.
  6. In VS Code, press Ctrl+Shift+P, type Git: Clone, press Enter, and paste the URL you copied. Choose a folder on your computer to save it in.
Option B: Start in VS Code and publish from there

Use this when the project's files already exist on your computer and you want to turn them into a GitHub repository without ever opening a browser. This uses VS Code's own built-in Publish to GitHub button — no extra extension is required for it, it ships with VS Code itself.

  1. Open the project's folder in VS Code (File → Open Folder).
  2. Open the Source Control panel (Ctrl+Shift+G) and click Initialize Repository if it isn't one already.
  3. Stage and commit your files (see "Push a commit from VS Code" below).
  4. Click Publish Branch. VS Code asks whether the new repository should be Public or Private.
  5. Pick one. VS Code creates the repository on GitHub for you and pushes your code to it in the same step. Nothing exists on github.com until this exact moment.
Same destination, two different starting points.
 Option A: GitHub website firstOption B: Publish from VS Code
Best whenThe project doesn't exist as files yetThe project's files already exist on your computer
Where the repo is created firstgithub.comVS Code, then pushed up automatically
Extra tools neededNoneNone — this is built into VS Code
Extra step requiredClone it down afterwardNone, publishing does both steps at once

What the "GitHub Pull Requests and Issues" extension actually adds. It's easy to assume this extension is what creates the repository, since "Publish to GitHub" sounds like exactly what it would do — but that button is already part of VS Code itself. The extension's real job is different: once a repository exists, it lets you create, review, comment on, and merge pull requests, and browse issues, all without leaving VS Code or opening a browser. It's genuinely useful once you're collaborating with other people on a repo, but it is not required for either option above.

One-Time Setup

Set your name and email for commits

Signing in to GitHub inside VS Code and setting your Git identity are two different things. Every commit records an author name and email pulled from your local Git configuration, not from your GitHub login, so set it once per machine in the VS Code terminal (Ctrl+`):

git config --global user.name "Your Name" git config --global user.email "[email protected]"
The Vocabulary

The core Git commands, explained

VS Code's buttons run these commands for you behind the scenes. Knowing what each one actually does makes the buttons, and the error messages, make sense.

git init

Turns the current folder into a Git project by creating a hidden .git subfolder that will hold the entire history of every change you ever commit. You run this exactly once, at the very start of a new project. Clicking "Initialize Repository" in VS Code runs this for you.

git init
git add

Tells Git which changed files you want included in the next commit. This is called staging. Clicking the + next to a file in VS Code's Source Control panel does this for you, one file, or all of them, at a time.

git add .
git commit

Saves a permanent snapshot of everything you just staged, labeled with a message describing what changed. Every commit is a point in history you can always come back to. Clicking the checkmark in VS Code's Source Control panel runs this with whatever message you typed in the box above it.

git commit -m "message"
git branch

Creates a new, separate line of history you can experiment on without touching main. Run by itself with no name, it instead lists every branch that already exists, with a * next to whichever one you're currently on.

git branch feature-x
git remote

Saves a short nickname, almost always origin, for a repository's full URL on GitHub, so every later command can say origin instead of retyping the whole address. Cloning or publishing sets this up automatically; git remote -v shows what it's currently pointing at.

git remote add origin <url> git remote -v
git push

Uploads your local commits to the remote repository on GitHub, so they're backed up and anyone with access can see them. Nothing you commit is actually on GitHub until you push it. VS Code's Sync Changes or Publish Branch button runs this for you.

git push origin main

In order, a brand new project usually goes: git init once, then git add and git commit every time you save progress, then git remote add origin <url> once (or automatically, if you cloned or published), then git push every time you want that progress on GitHub.

Step by Step

Push a commit from VS Code

This is the everyday workflow once a repo exists and you're signed in. Do this every time you want to save your progress and send it to GitHub.

  1. Edit your files as normal. VS Code marks changed files with an M and new files with a U in the file explorer.
  2. Open the Source Control panel (Ctrl+Shift+G). Every changed file is listed under Changes.
  3. Hover over a file and click the + to stage it, or click the + next to Changes to stage everything. (This is git add.)
  4. Type a short, specific commit message in the text box at the top (for example, fix: handle empty input in grade calculator).
  5. Click the checkmark, or press Ctrl+Enter, to commit. This saves the snapshot locally — it has not left your computer yet. (This is git commit.)
  6. Click Sync Changes (or Push, if that's what the button says) to send your commit to GitHub. The first push of a new local repo may ask you to Publish Branch instead. (This is git push.)

The same steps from the terminal, if you prefer typing commands:

git status # see what's changed git add . # stage all changes git commit -m "message" # save a snapshot locally git push origin main # send it to GitHub git pull # get the latest changes from GitHub git clone <url> # copy a repo from GitHub
When It Won't Cooperate

Troubleshooting connection issues

"Support for password authentication was removed"

GitHub no longer accepts your account password over Git. Sign out and back in through VS Code's Accounts icon (bottom left corner) so it re-runs the browser sign in flow and refreshes your token. Don't type your GitHub password when a terminal prompt asks for one.

"Permission denied (publickey)"

Your remote URL is using SSH ([email protected]:...) and no SSH key is set up. Switch the remote to HTTPS instead, which is what VS Code's sign in flow authenticates: git remote set-url origin https://github.com/user/repo.git.

Stuck on an old or wrong account

Click the Accounts icon in the bottom left corner of VS Code, sign out of GitHub completely, then push again to trigger a fresh sign in prompt. A stale cached credential is the most common cause of pushes failing after a password or 2FA change.

Push hangs or times out

Campus or work networks sometimes block Git's SSH port (22) but allow HTTPS (443). Confirm your remote uses an https:// URL, not git@, and try again on a different network if it still hangs.

"git is not recognized" in the terminal

Git isn't installed, or VS Code was open before you installed it. Install Git from git-scm.com, then fully close and reopen VS Code so its integrated terminal picks up the updated system PATH.

Push rejected: "fetch first" or "non-fast-forward"

GitHub has commits you don't have locally, usually from editing a file directly on github.com or pushing from a second computer. Run git pull to merge them in, resolve any conflict markers VS Code highlights, then push again.