Every software engineer uses Git. This page walks through installing it, connecting VS Code to your GitHub account, the two ways to actually get a project onto GitHub, what the core commands mean, and what to do when the connection won't cooperate.
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.
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.
Ctrl+Shift+G.git init command for you — explained in detail further down this page.)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.
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.
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.
Ctrl+Shift+P, type Git: Clone, press Enter, and paste the URL you copied. Choose a folder on your computer to save it in.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.
Ctrl+Shift+G) and click Initialize Repository if it isn't one already.| Option A: GitHub website first | Option B: Publish from VS Code | |
|---|---|---|
| Best when | The project doesn't exist as files yet | The project's files already exist on your computer |
| Where the repo is created first | github.com | VS Code, then pushed up automatically |
| Extra tools needed | None | None — this is built into VS Code |
| Extra step required | Clone it down afterward | None, 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.
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]"
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 initTurns 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 initgit addTells 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 commitSaves 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 branchCreates 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-xgit remoteSaves 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 -vgit pushUploads 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 mainIn 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.
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.
Ctrl+Shift+G). Every changed file is listed under Changes.git add.)fix: handle empty input in grade calculator).Ctrl+Enter, to commit. This saves the snapshot locally — it has not left your computer yet. (This is git commit.)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
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.
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.
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.
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 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.
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.