Chapter 7 of 10 · Git and GitHub for Beginners — Complete Free Tutorial

Working with Remotes and GitHub

Everything so far has lived on your machine. This seventh chapter of the Git and GitHub for Beginners series adds the piece that turns a personal habit into teamwork: the remote. You will connect your repository to GitHub, push your commits, and learn the fetch/pull/push rhythm that keeps two copies of a project in step.

What a remote actually is

A remote is another copy of your repository that lives somewhere else — usually on GitHub. It has a short name (by convention origin) and a URL. Your local repository keeps its full history either way; the remote is a destination you push to and a source you fetch from. Knowing which copy you are looking at answers half of all Git confusion: local means your laptop, remote means the server, and origin/main means “what main looks like on GitHub as of my last fetch”.

Clone, fork, or fresh start

There are three ways to get a GitHub repository onto your disk, and beginners mix them up constantly:

MethodWhat you getWhen to use it
git cloneA full copy with history, with origin already configuredStarting work on any existing repository
Fork on GitHub, then cloneYour own GitHub repository linked to the original as upstreamContributing to a project you do not control
Download ZIPFiles only — no history, no remoteBrowsing a demo; never for real work

Cloning also downloads every branch and commit, so you can browse the past immediately. Forking is a GitHub-side concept, not a Git command — it simply gives you a remote to push to when you lack write access.

Publishing your own repository

For a project you started locally, the flow is: create an empty repository on GitHub (no README, so histories do not clash), add it as a remote, then push. The -u flag on the first push is worth remembering — it sets up tracking, so later you can simply type git push and git pull without arguments. Authentication is either a HTTPS URL with a personal access token, or an SSH key (git@github.com:...) configured once and remembered forever.

Fetch versus pull

Both download new commits from the remote, but they differ in one crucial way:

  • git fetch downloads only — it updates origin/main and leaves your main and your files untouched. Always safe, always worth running.
  • git pull fetches and then merges (or rebases) into your current branch. Convenient, but it changes your working tree and can raise conflicts.

A reliable habit: fetch, review with git log --oneline main..origin/main, then merge when you are ready. If someone pushed while you were working, Git refuses the push and tells you to pull first — that rejection is a feature, not an insult.

Keeping every branch in view

git remote -v lists your remotes with their fetch and push URLs. git branch -a shows local branches alongside remote-tracking branches, and git push origin main publishes a branch by name. When a remote branch is deleted, git fetch --prune (or git pull --prune) tidies your stale origin/... references so the list matches reality.

git remote add origin git@github.com:sara-bakery/bakery-site.git
git push -u origin main

Expected output:

Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Writing objects: 100% (12/12), 3.42 KiB | 3.42 MiB/s, done.
To github.com:sara-bakery/bakery-site.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main' from 'main'.
git fetch origin
git log --oneline main..origin/main

Expected output:

7a8b9c0 Update the menu prices from the owner's feedback
2e3d4f5 Add opening-hours schema markup
git remote -v

Expected output:

origin	git@github.com:sara-bakery/bakery-site.git (fetch)
origin	git@github.com:sara-bakery/bakery-site.git (push)

Common mistakes

  • Adding a remote to a URL that already contains a repository — the name must be short (origin), the URL goes in git remote add.
  • Pushing without pulling first — a non-fast-forward push is rejected; run git pull and reconcile before trying again.
  • Confusing origin/main with main — the first is what GitHub had at your last fetch, the second is your local branch.
  • Skipping -u on the first push — every later push needs explicit arguments until tracking is set.
  • Treating git pull as a harmless refresh — it merges into your branch and can conflict; fetch when you only want to look.

Practice checklist

  1. Create an empty repository on GitHub and copy its SSH or HTTPS URL.
  2. Run git remote add origin <url> in your practice repo, then confirm with git remote -v.
  3. Push main with git push -u origin main and refresh GitHub to see your files.
  4. Make a commit on GitHub's web editor (or a teammate's push), then git fetch and list it with git log --oneline main..origin/main.
  5. Run git pull and confirm your local branch now matches the remote.

What's next?

Pushing to a shared branch is only the start of collaboration. Continue to Pull Requests and Code Review to learn how teams review work before it lands.

Quiz: Working with Remotes and GitHub

5 questions · 70% to pass

Frequently Asked Questions

Git is a distributed version control system: it records snapshots of your project over time, lets you jump back to any point, branch off to try ideas safely, and merge other people's work. It is the industry standard — nearly every developer job assumes basic Git fluency — and it is the best insurance you can have against lost or broken code.

Git is the tool that runs on your machine and stores history locally; it works fully offline. GitHub is one of many websites (GitLab, Bitbucket) that hosts Git repositories in the cloud and adds collaboration features: pull requests, code review, issues and CI. You can use Git forever without GitHub — GitHub needs Git to be useful.

A repository (repo) is your project folder plus a hidden .git directory containing the entire history: every commit, branch and tag. It can be local (only on your computer) or remote (cloned on GitHub). Deleting .git loses the history but keeps your files; deleting the files while keeping .git leaves history with nothing to show.

git add moves changed files into the staging area — your draft of the next snapshot — so you can review exactly what will be recorded. git commit writes the staged snapshot permanently with a message describing why the change happened. Two steps by design: stage deliberately, commit intentionally.

A branch is a movable pointer to a commit — creating one costs almost nothing. Use a branch for every unit of work (feature, fix, experiment): it keeps unfinished code out of main, lets you review changes in a pull request, and makes abandoning a bad idea as simple as deleting the branch.

It depends on where the change lives. Unstaged edits: git restore file. Staged but uncommitted: git restore --staged file. Committed but not pushed: git reset --soft to keep changes staged. Already pushed: git revert commit — it writes a new commit that undoes the old one instead of rewriting shared history. The undoing chapter covers each case with commands.

A conflict happens when two branches changed the same lines and Git cannot choose automatically. Your file gets marked up with <<<<<<<, ======= and >>>>>>> sections; you edit it down to the correct result, remove the markers, then git add and git commit. Conflicts are normal, small and entirely fixable — they are not an error state.

A pull request (PR) is GitHub's proposal to merge one branch into another. It shows the diff, runs checks, and lets teammates comment line by line before the code lands. It is the centre of modern collaboration: work on a branch, open a PR, review, approve, merge.

Write the subject in imperative mood, under about 50 characters: "Add email validation to signup". Explain why, not what, in the body when it is not obvious. Many teams use Conventional Commits (feat:, fix:, docs:) so tools can generate changelogs — the workflows chapter shows the format in practice.

Secrets (API keys, .env files), dependencies (node_modules), build output (dist), and operating-system junk (.DS_Store, Thumbs.db). A .gitignore file excludes them from the start; the common mistakes chapter shows what to do if something already slipped into history.