Working Across Machines
Git repos are not tied to one computer. You can clone a repo to any machine, keep multiple clones in sync, and collaborate by forking public repos on GitHub.
Clone a Repo
git clone downloads a complete copy of a remote repo — all history, all branches, all files:
git clone git@github.com:<username>/my-first-repo.git my-repo-copy
This creates a folder called my-repo-copy with the full repo inside. The remote is automatically configured as origin.
Fetch vs. Pull
Two ways to bring in remote changes:
git fetch # downloads remote changes, doesn't touch your working files
git pull # fetch + merge: downloads and updates your current branch
Use git fetch when you want to inspect what is new before integrating it:
git fetch
git log origin/main --oneline # see what arrived
git pull # bring it in when ready
Simulate Two Machines
This exercise shows how sync works in practice:
-
In
my-repo-copy(your second clone), make a commit and push:cd my-repo-copyecho "Change from clone 2" >> README.mdgit add README.mdgit commit -m "Edit from second clone"git push -
In your original
my-first-repo, pull the change:cd my-first-repogit pullgit log --oneline # you will see the commit from the other clone
This is exactly what happens when you and a teammate both have clones of the same repo.
Forking
A fork is a full copy of someone else's GitHub repo under your own account. It is how open-source contribution works: you fork the repo, make changes on your fork, and then open a PR from your fork back to the original.
Try it now
- Go to github.com/octocat/Hello-World.
- Click Fork (top-right) → Create fork.
- Clone your fork:
git clone git@github.com:<username>/Hello-World.git
- Make a small change, commit, push to your fork.
- You would normally open a PR from your fork back to the original — you can try it if you like.
Summary
| Command | What it does |
|---|---|
git clone <url> | Download a full copy of a remote repo |
git fetch | Download remote changes, do not merge |
git pull | Fetch and merge into current branch |
| Fork (GitHub UI) | Copy someone else's repo to your account |