Computing Foundations › Git and GitHub › Day 32

Day 32: Remotes and GitHub

Day 32 of 365 — Remotes and GitHub

After this lesson you will be able to connect a local Git repository to another copy of itself — a remote — and move commits between them with clone, fetch, pull, and push, understanding exactly what each does and how hosting platforms like GitHub build on top of that connection.

Course
Computing Foundations
Category
Git and GitHub
Reading time
≈ 40 min
Practical time
≈ 30 min
Lesson duration
1h 10m
Last verified
2026-07-12

Hands-on lab for this lesson

Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/computing-foundations/day-032-remotes-and-github

  1. Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
    git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git
    cd ai-roadmap-365.github.io
  2. Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
    cd labs/sections/computing-foundations/day-032-remotes-and-github
  3. Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
  4. Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
    bash tests/run_tests.sh   # or the test command named in the lab README

You can also open the lab as a local page (works offline, shows the file tree and expected output).

Learning objectives

By the end of this lesson you will be able to:

Prerequisites

Why this matters


The idea in plain language

Diagram: commands that move commits compared with commands that integrate them


Historical background

Diagram: a centralised server compared with peer repositories


What it is — and what it is not

A remote is:

It is not:


Why it was created and what problems it solves


How it works

The two halves

Diagram: how a remote-tracking branch mirrors a remote branch

Diagram: a local repository and a remote named origin, linked by fetch and push, with a tracking branch mirroring the remote branch

The four operations

Diagram: the four remote operations — clone, fetch, pull, and push — and what data each one moves between the remote and your local repository

The commands

CommandWhat it doesDirection
git remote -vLists remotes and their URLslocal inspection
git remote add <name> <url>Registers a new remotelocal config
git clone <url>Copies a remote, sets up originremote → new local repo
git fetch <remote>Downloads commits; updates tracking branchesremote → local, no merge
git pullFetches, then merges upstream into your branchremote → your branch
git pushUploads your commitsyour branch → remote
git push -u origin mainPushes and sets the upstreamyour branch → remote
git branch -vvEach branch, its upstream, and how far ahead or behindlocal inspection

An everyday analogy

Diagram: a fork compared with a clone

Two people keeping the same notebook.

The notebooksGit remotes
Your own complete notebookYour local repository
The shared copy in the officeorigin
Your note of what the office copy saidorigin/main
Going to read the office copyFetch
Copying its new pages into yoursMerge
Doing both in one tripPull
Writing your new pages into itPush

Examples in practice

Diagram: the cause of a rejected push and how to resolve it


Implications: security, privacy, performance, scalability, and cost

Diagram: a commit that exists only locally compared with one that has been pushed


Alternatives: free, open source, and commercial

Diagram: what a git clone actually transfers

OptionTypeWhere it fits
A hosting platformFree tiers, commercialCollaboration, review, issues, automation
A self-hosted serverFree, open sourceFull control; you also run the backups
A bare repository on any serverFreeA remote needs nothing but SSH access and a directory
A second local cloneFreeA genuine remote, useful for practice and for a spare disk
Git LFSFree, open sourceLarge binaries kept out of the main history
SSH keys / platform tokensFreeHow you authenticate; prefer either to a password

Diagram: SSH keys compared with access tokens

TermWhat it actually is
RemoteA named URL for another copy of the repository
originThe conventional name for the one you cloned from
Remote-tracking branchYour read-only mirror of a remote branch
UpstreamThe remote branch your local branch is paired with
FetchDownload commits; change nothing you are working on
PullFetch, then merge
ForkA platform feature: your own server-side copy

When to use it — and when not to

Diagram: fetching and inspecting before merging


The AI connection

Diagram: what becomes public when a repository is pushed


Knowledge check

quiz:
  question: "You run `git fetch` and it reports new commits, but `git status` still says your branch is up to date with nothing to merge. What happened?"
  options:
    - "Fetch updated the remote-tracking branch only; your local branch has not moved and needs a merge"
    - "The fetched commits belong to a different branch and are not relevant to yours"
    - "Fetch downloaded the commits but they were rejected because your branch has diverged"
    - "git status compares against the last commit, not against the remote"
  answer_index: 0
  explanation: "Fetch moves origin/main and touches nothing else — that is exactly what makes it safe. Your own branch is unchanged until you merge, which is what pull would have done in the same step."

Hands-on exercise

Create a remote, push to it, and provoke a rejection. Worked through fully in the Day 32 lab directory.

What you are doingCommand
Make a bare repository to act as a remotegit init --bare ../remote.git
Register itgit remote add origin ../remote.git
Inspect the remotesgit remote -v
Push and set upstreamgit push -u origin main
See branch tracking stategit branch -vv
Clone it elsewhere and commitgit clone ../remote.git other && cd other
Provoke a rejectionCommit in both clones, push from both
Recovergit fetch then git merge origin/main, then push

Expected output

origin  ../remote.git (fetch)
origin  ../remote.git (push)
* main 712412c [origin/main] Add request handler
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs
hint: Updates were rejected because the remote contains work that you do not have

Validate your work

Troubleshooting

Common mistakes


Practice assignment


Extension challenge


Quiz

Q1. What is a Git remote?

  1. A cloud account you must create before Git will work
  2. A backup service built into the Git program
  3. A branch that only exists on the internet
  4. A named reference to another copy of the repository
Show answer

Answer: D. A named reference to another copy of the repository

A remote is simply another copy of the repository — on a server, a peer machine, or even a local folder — together with a short name (like "origin") your Git uses to refer to it. Nothing about it requires the cloud or an account.

Q2. What is the difference between git fetch and git pull?

  1. Fetch only downloads; pull downloads and then merges
  2. They are two names for the same command
  3. Fetch uploads commits; pull downloads them
  4. Pull works offline while fetch requires a network
Show answer

Answer: A. Fetch only downloads; pull downloads and then merges

git pull is defined as git fetch followed by a merge. Fetch is the safe download-only step that updates origin/main without changing your files; pull additionally integrates those commits into the branch you are on.

Q3. When you run git clone, what name does Git give the remote it sets up automatically?

  1. main
  2. origin
  3. upstream
  4. master
Show answer

Answer: B. origin

Clone records one remote and names it "origin" by convention, meaning "the place this repository came from." The name is only a default — you can rename it or add others — but "origin" is what you will see almost everywhere.

Q4. What is the relationship between Git and GitHub?

  1. GitHub is the version-control tool; Git is a website that hosts it
  2. They are the same product under two names
  3. Git is the tool on your machine; GitHub hosts remotes
  4. Git only works if you have a GitHub account
Show answer

Answer: C. Git is the tool on your machine; GitHub hosts remotes

Git is the distributed version-control engine; GitHub, GitLab, and Bitbucket are platforms built around Git remotes, adding a website, permissions, issue tracking, and more. You can use Git for years with no GitHub account.

Q5. You try to git push and Git rejects it, saying the remote contains work you do not have locally. What is the correct response?

  1. Force the push to overwrite the remote
  2. Delete your local branch and start over
  3. Create a new remote and push there instead
  4. Run git pull first, then push again
Show answer

Answer: D. Run git pull first, then push again

The rejection is a safety feature preventing you from silently overwriting someone else's work. The correct, safe sequence is to fetch and merge the remote's new commits into your branch, then push the reconciled result.

Q6. Which statement about a remote-tracking branch such as origin/main is correct?

  1. A read-only mirror of the remote branch that Git updates
  2. It is the branch you commit to when working offline
  3. It is a separate copy of the whole repository
  4. It is automatically deleted after every push
Show answer

Answer: A. A read-only mirror of the remote branch that Git updates

origin/main is your machine's mirror of where the remote's main branch was as of your last communication with it. You never commit to it directly; Git moves it during fetch and pull, and your local main is the branch you actually edit.

Q7. How does SSH-key authentication prove your identity to a remote, compared with HTTPS?

  1. It sends your account password encrypted over the web port
  2. A private key never leaves your machine; nothing secret is sent
  3. It requires you to paste a token on every push
  4. It disables authentication entirely for trusted networks
Show answer

Answer: B. A private key never leaves your machine; nothing secret is sent

With SSH you generate a key pair, upload the public key once, and your machine proves it holds the matching private key through a handshake — no password or token is transmitted. HTTPS instead presents a username and a revocable personal access token.

Q8. What is the difference between cloning a repository and forking it?

  1. Cloning is free; forking costs money
  2. Forking downloads only the latest commit; cloning downloads everything
  3. Cloning copies locally; forking copies on the platform
  4. They are identical operations
Show answer

Answer: C. Cloning copies locally; forking copies on the platform

Clone brings a repository down to your local machine. Fork creates a copy under your own account on the hosting platform — essential when you want to propose changes to a project you have no write access to, since you can push to your fork and then propose merging it back.

Glossary

remote
A named reference to another copy of a Git repository — on a server, a peer machine, or a local folder — that your repository can synchronise with.
origin
The conventional default name Git gives the remote a repository was cloned from; it means "the place this repository came from."
clone
The command that creates a new local copy of a remote repository, including its full history, and sets up the origin remote and tracking branches automatically.
fetch
The command that downloads new commits from a remote and updates the remote-tracking branches, without changing your working branch or files.
pull
The command that fetches from a remote and then merges the downloaded commits into your current branch; equivalent to a fetch followed by a merge.
push
The command that uploads your local commits to a remote so other copies of the repository can receive them.
upstream
The specific remote branch a local branch is paired with, so that a bare git push or git pull knows where to send and receive commits.
tracking branch
A read-only local mirror of a remote branch, such as origin/main, that Git updates for you during fetch and pull; also called a remote-tracking branch.
SSH key
A cryptographic key pair used to authenticate to a remote: a private key stays on your machine and a public key is uploaded once, and your identity is proven by a handshake with no secret transmitted.
personal access token
A long, random, revocable secret used in place of an account password when authenticating to a hosting platform over HTTPS; it can be scoped to specific permissions and given an expiry date.
fork
Your own server-side copy of someone else's repository on a hosting platform, which you can push to freely and use to propose changes back to the original.
bare repository
A repository that stores Git history but has no working directory of checked-out files; this is the form a server-side remote takes, and the lab uses one to act as a local "origin".
hosting platform
A service such as GitHub, GitLab, or Bitbucket that hosts Git remotes and adds a website, access control, issue tracking, code review, and automation on top of Git.

Sources and further reading


Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.