Computing Foundations › Git and GitHub › Day 32
Day 32: 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.
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
- 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 - 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 - 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.
- 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:
- Define a remote as a named reference to another copy of a repository, and explain what "origin" and "upstream" mean
- Move commits between repositories with git clone, git fetch, git pull, and git push, and state precisely how fetch and pull differ
- Explain what a remote-tracking branch (origin/main) is and how it relates to your local branch
- Distinguish Git from a hosting platform, and describe what GitHub, GitLab, Bitbucket, and self-hosted Gitea add on top of a Git remote
- Compare HTTPS-with-a-token and SSH-key authentication: how each proves identity, and when to choose each
- Distinguish public from private repositories and cloning from forking, and simulate a full push/fetch/pull cycle against a local bare repository with no network
Prerequisites
- Days 29–31: version control concepts, Git repositories, staging and commits, and branching and merging
- A terminal with Git installed (macOS, Linux, or Windows with WSL); no GitHub account or network is required for the lab
Why this matters
-
A repository on one disk is one failure from gone. A remote is the second place it lives.
-
Every model, dataset and framework you use was obtained by cloning from a remote.
-
Collaboration begins here. Everything before today worked alone.
-
git pushbeing rejected is a safety feature, and understanding why turns a frustrating message into an obvious one. -
A public repository is your portfolio, and it is how shared work — including trained models — reaches anyone.
The idea in plain language
-
A remote is another copy of the repository, somewhere you can reach.
-
It is a name paired with a URL, stored in your repository’s configuration.
originis the conventional name for the one you cloned from. -
Fetch and push move commits between repositories. Pull and merge integrate them into a working branch.
-
Every confusing remote moment resolves once you know which of those two things is happening.
-
Nothing is automatic. Git never contacts a remote unless you tell it to.
Historical background
-
Centralised systems had one repository, on a server, and everyone else had a working copy. You could not commit offline.
-
Git inverted that. Every clone is a full repository, so there is no technical centre at all.
-
The “central” repository is a social convention, not a technical one.
originis a default name, not a special kind of thing. -
Hosting platforms added what Git deliberately lacks: access control, an issue tracker, code review, and automation.
-
The pull-request workflow was invented on those platforms, not in Git, and it is what made open-source contribution from strangers practical.
-
The vocabulary stuck. “Origin”, “upstream” and “fork” all come from that era and none of them are Git concepts.
What it is — and what it is not
A remote is:
- A named URL pointing at another copy of the repository.
- A destination for pushes and a source for fetches.
- Entirely optional. Git works completely without one.
It is not:
-
Not the “real” repository. Yours is just as complete, and there is no technical hierarchy.
-
Not a backup by itself, unless you actually push. An unpushed commit exists on one disk.
-
Not automatically synchronised. Nothing crosses the network until you ask.
-
Not the same as the hosting platform. Issues, reviews and permissions are the platform’s; the remote is just a repository.
Why it was created and what problems it solves
-
Backup and durability. A repository on one disk is one spilled coffee from gone. Pushing means the full history lives in at least two places.
-
Collaboration. Before distributed version control, teams shared a server and effectively took turns; if it was down, or you were offline, you were stuck.
-
Working apart. Everyone holds a complete repository and synchronises when convenient, so two people can work from different continents on different schedules and reconcile afterwards.
-
Publication. A remote on a public platform is an address others can clone from.
-
Distribution. This is how open source spreads, how a portfolio is seen, and how shared models and datasets reach the people who need them.
How it works
The two halves
-
Git stores a small list of remotes in its configuration — each a name paired with a URL. Cloning writes the
originentry automatically. -
Your local
mainis the branch you edit and commit to. -
origin/mainis a remote-tracking branch: your machine’s best guess about where the remote’smainis. -
It is a read-only mirror, updated only when you communicate with the remote. You never commit to it; Git moves it during fetch and pull.
-
A local branch paired with a remote branch has an upstream, and once set, plain
git pushandgit pullknow where to go.
The four operations
-
Clone copies the entire history to a new local repository and sets up
originand tracking branches in one step. Once per machine. -
Fetch downloads commits you do not have and advances
origin/main. Your ownmaindoes not move and no working file changes — it is the safe “show me what is new” command. -
Pull is exactly a fetch followed by a merge of
origin/maininto your current branch. Which means it can produce a merge, and occasionally a conflict, like any other merge. -
Push sends your commits up and advances the remote’s branch to match. Git refuses if the remote has commits you do not — that rejection is a safety feature, telling you to fetch and integrate first so you never silently overwrite someone else’s work.
-
The key model: fetch and push move commits between repositories; pull and merge integrate them into a working branch.
The commands
| Command | What it does | Direction |
|---|---|---|
git remote -v | Lists remotes and their URLs | local inspection |
git remote add <name> <url> | Registers a new remote | local config |
git clone <url> | Copies a remote, sets up origin | remote → new local repo |
git fetch <remote> | Downloads commits; updates tracking branches | remote → local, no merge |
git pull | Fetches, then merges upstream into your branch | remote → your branch |
git push | Uploads your commits | your branch → remote |
git push -u origin main | Pushes and sets the upstream | your branch → remote |
git branch -vv | Each branch, its upstream, and how far ahead or behind | local inspection |
An everyday analogy
Two people keeping the same notebook.
| The notebooks | Git remotes |
|---|---|
| Your own complete notebook | Your local repository |
| The shared copy in the office | origin |
| Your note of what the office copy said | origin/main |
| Going to read the office copy | Fetch |
| Copying its new pages into yours | Merge |
| Doing both in one trip | Pull |
| Writing your new pages into it | Push |
-
Your note of what the office copy said goes stale the moment someone else writes in it. That is why fetch exists.
-
You cannot write your pages in if someone added pages you have not read — you would overwrite them. That refusal is the point.
-
Both notebooks are complete. Neither is the original.
Examples in practice
-
Updates were rejected because the remote contains work that you do not have— fetch, integrate, then push. This is the message the safety feature produces. -
git fetchshowing new commits whilegit statussays you are up to date, because fetch updated the tracking branch and not your branch. -
A pull that produces a merge commit you did not expect, because the branch had diverged.
-
A push that succeeded to the wrong remote, because a fork and an upstream were both configured.
-
A clone that took ten minutes because someone committed a dataset years ago and every clone still carries it.
Implications: security, privacy, performance, scalability, and cost
-
Security: pushing publishes. Everything in the history goes, including anything committed by mistake at any point in the past.
-
A secret pushed to a public repository is found in minutes by automated scanners. Revoke it; do not merely remove it.
-
Use SSH keys or a token, never a password. Platform tokens can be scoped and revoked individually.
-
Privacy: your commits carry your name and email, and they become public with the repository. Configure them deliberately.
-
Performance: clone cost is the whole history, not the current files, which is why one large binary committed once slows every clone forever.
-
git fetchis cheap;git cloneis not. Shallow clones exist for CI, where the history is not needed. -
Cost: an unpushed commit is not backed up. The habit of pushing at the end of a session is the whole of the insurance.
Alternatives: free, open source, and commercial
| Option | Type | Where it fits |
|---|---|---|
| A hosting platform | Free tiers, commercial | Collaboration, review, issues, automation |
| A self-hosted server | Free, open source | Full control; you also run the backups |
| A bare repository on any server | Free | A remote needs nothing but SSH access and a directory |
| A second local clone | Free | A genuine remote, useful for practice and for a spare disk |
| Git LFS | Free, open source | Large binaries kept out of the main history |
| SSH keys / platform tokens | Free | How you authenticate; prefer either to a password |
-
A remote does not require a platform. Any machine you can reach over SSH can hold one, which is worth knowing when a platform is not an option.
-
Set up SSH keys once and stop typing credentials. It is the single largest quality-of-life improvement in this lesson.
Comparison with related concepts
| Term | What it actually is |
|---|---|
| Remote | A named URL for another copy of the repository |
origin | The conventional name for the one you cloned from |
| Remote-tracking branch | Your read-only mirror of a remote branch |
| Upstream | The remote branch your local branch is paired with |
| Fetch | Download commits; change nothing you are working on |
| Pull | Fetch, then merge |
| Fork | A platform feature: your own server-side copy |
When to use it — and when not to
-
Push at the end of every working session. An unpushed commit is not backed up.
-
Prefer
fetchthen look, overpull, when you want to know what changed before integrating it. -
Use
git push -uthe first time so later pushes need no arguments. -
Read a push rejection rather than forcing past it. It is telling you someone else’s work is at risk.
-
Do not force-push a shared branch. That is Day 31’s rebase rule, arriving with consequences.
-
Do not commit large files into a repository that others will clone.
-
Do not assume pushed means reviewed. Pushing is publication, not approval.
The AI connection
-
Cloning a model repository is how you get weights, configs and tokenizer files — and why some of them take a very long time.
-
Model hubs are Git remotes with large-file support, which is why the workflow feels familiar and the download does not.
-
Push your experiment code before a long training run, so the state that produced the result exists somewhere other than the machine running it.
-
A public repository is how your work is found. For AI work specifically, a readable repository is worth more than a described one.
-
Never push a
.envor a checkpoint directory. Both are common, both are expensive, and both are prevented by a.gitignorewritten on Day 30.
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 doing | Command |
|---|---|
| Make a bare repository to act as a remote | git init --bare ../remote.git |
| Register it | git remote add origin ../remote.git |
| Inspect the remotes | git remote -v |
| Push and set upstream | git push -u origin main |
| See branch tracking state | git branch -vv |
| Clone it elsewhere and commit | git clone ../remote.git other && cd other |
| Provoke a rejection | Commit in both clones, push from both |
| Recover | git 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
[origin/main]inbranch -vvis the upstream pairing.- The rejection is the safety feature. Fetch, integrate, then push — never force.
Validate your work
- You created a remote without any hosting platform
- You pushed and confirmed the upstream was set
- You cloned into a second directory and committed there
- You provoked a push rejection and recovered from it correctly
- You can explain what
git fetchchanged and what it did not -
bash tests/run_tests.shreports 0 failures
Troubleshooting
-
src refspec main does not match any. You have no commits yet. Commit first. -
no upstream branch. Usegit push -u origin mainonce; after that plaingit pushworks. -
A pull produced a merge commit you did not want. The branches had diverged.
git pull --rebaseis the alternative — subject to Day 31’s rule. -
Authentication fails. Use an SSH key or a platform token, not a password.
Common mistakes
- Forcing past a rejection, which discards someone else’s commits.
- Committing but never pushing, and calling it backed up.
- Confusing
origin/mainwithmain. One is a mirror; the other is yours. - Pushing a
.envthat a.gitignoreshould have excluded.
Practice assignment
-
Set up a remote and two clones, and simulate two people working: commit in both, push from both, and resolve the rejection properly.
-
Use
git fetchfollowed bygit log origin/mainto inspect incoming work before integrating it, and describe what changed before merging. -
Configure SSH keys for a hosting platform and confirm you no longer type credentials.
-
Find a repository whose clone is slow and identify what is making it large.
Extension challenge
-
Add a second remote — an upstream as well as your own fork — and practise fetching from one and pushing to the other. This is the standard open-source shape.
-
Make a shallow clone with
--depth 1and compare its size and clone time with a full one. Then find out what you cannot do with it. -
Recover a commit that only existed locally on a machine you then wiped — or prove to yourself that you cannot, which is the more useful lesson about pushing.
-
Inspect what a push actually sends with
GIT_TRACE=1, and confirm that only missing objects cross the network.
Quiz
Q1. What is a Git remote?
- A cloud account you must create before Git will work
- A backup service built into the Git program
- A branch that only exists on the internet
- 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?
- Fetch only downloads; pull downloads and then merges
- They are two names for the same command
- Fetch uploads commits; pull downloads them
- 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?
- main
- origin
- upstream
- 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?
- GitHub is the version-control tool; Git is a website that hosts it
- They are the same product under two names
- Git is the tool on your machine; GitHub hosts remotes
- 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?
- Force the push to overwrite the remote
- Delete your local branch and start over
- Create a new remote and push there instead
- 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?
- A read-only mirror of the remote branch that Git updates
- It is the branch you commit to when working offline
- It is a separate copy of the whole repository
- 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?
- It sends your account password encrypted over the web port
- A private key never leaves your machine; nothing secret is sent
- It requires you to paste a token on every push
- 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?
- Cloning is free; forking costs money
- Forking downloads only the latest commit; cloning downloads everything
- Cloning copies locally; forking copies on the platform
- 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
- Git Basics — Working with Remotes — Chacon & Straub / Pro Git (accessed 2026-07-12)
- About remote repositories — GitHub Docs (accessed 2026-07-12)
- Connecting to GitHub with SSH — GitHub Docs (accessed 2026-07-12)
- git-push Documentation — Git (accessed 2026-07-12)
- About GitHub and Git — GitHub Docs (accessed 2026-07-12)
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.