Push & Pull

What's a "remote"?

A remote is just a copy of your repository that lives somewhere else — usually on GitHub. By convention the main remote is nicknamed origin. When you clone a repo, origin is set up for you automatically. When you start a repo with git init, you connect it to GitHub yourself.

Connecting a new repo to GitHub

First create an empty repository on GitHub (click New on github.com). It gives you a URL. Then point your local repo at it:

Link local repo to GitHub (one time)

Terminal
$ git remote add origin https://github.com/you/project.git
$ git branch -M main
$ git push -u origin main
In VS Code
  1. With changes committed, open the Source Control panel
  2. Click Publish to GitHub (the button VS Code shows before a remote exists) — it creates the GitHub repo and pushes in one go
  3. Choose public or private when prompted. If the repo already has a remote, the button reads Publish Branch instead

The -u in 'push -u' links your local 'main' to GitHub's 'main' so future pushes are just 'git push'.

First push asks for a login? From the terminal, GitHub needs a token or an SSH key — Connect to GitHub walks through the one-time setup.

Sending commits up: push

git push uploads your local commits to GitHub. Commit locally as often as you like; push when you want to back up or share.

Upload your commits

Terminal
$ git push
In VS Code
  1. Click the Sync Changes button (the circular arrows) in the status bar
  2. Or use the '…' menu in Source Control → Push

A common beginner confusion: committing does NOT send anything to GitHub. Push is the step that does.

Bringing changes down: pull

When a teammate (or you, on another machine) pushes new commits, git pull downloads them and merges them into your current branch. Pull before you start working so you're up to date.

Get the latest changes

Terminal
$ git pull
In VS Code
  1. Click Sync Changes — it pulls and pushes in one action
  2. Or use the '…' menu → Pull

fetch vs pull

git fetch downloads new commits but doesn't change your files — it just lets you see what's new. git pull is really "fetch + merge" in one step. Beginners can stick with pull; fetch is handy when you want to look before you leap.

The daily rhythm: pull → make changes → addcommitpush. That loop covers most of what you'll ever do.

Push rejected? That "! [rejected] … (fetch first)" message just means GitHub has commits you don't — Push Rejected & Diverged Branches decodes it and shows the two-command fix.

Inspecting and managing remotes

See and manage your remotes

Terminal
$ git remote -v                         # list remotes and their URLs
$ git push -u origin my-feature         # push a NEW branch the first time
$ git push origin --delete old-branch   # delete a branch on GitHub
In VS Code
  1. Source Control → '…' → Remote lists and edits remotes
  2. Publish Branch handles the first push of a new branch

The -u (set-upstream) link is only needed the first time you push a new branch; after that, plain 'git push' works.

Working on someone else's project? Then you'll have two remotes — your fork (origin) and the original (upstream). Fork & Sync covers the whole flow.

Up next: the heart of teamwork on GitHub — proposing a change with a pull request, from branch to merge.

FAQ

Frequently Asked Questions

What does "origin" mean in Git?
It's the default nickname for your main remote — the GitHub copy of your repository. git push and git pull use origin unless you tell them otherwise.
Why was my git push rejected?
Almost always because GitHub has commits you don't have yet — git pull then git push fixes it. Push Rejected & Diverged Branches decodes the full message.
What is the difference between git fetch and git pull?
git fetch downloads new commits without changing your files. git pull is fetch plus merge — it downloads and updates your current branch in one step.
How do I connect an existing folder to GitHub?
Create an empty repository on GitHub, then run git remote add origin <url> and git push -u origin main.