Skip to main content

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 fetchGitHuborigin/maindownloadLocalorigin/mainDownloads but does NOTchange your working filesgit pullGitHuborigin/mainfetch+mergeLocalmain ✓Downloads AND updatesyour current branch
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:

  1. In my-repo-copy (your second clone), make a commit and push:

    cd my-repo-copy
    echo "Change from clone 2" >> README.md
    git add README.md
    git commit -m "Edit from second clone"
    git push
  2. In your original my-first-repo, pull the change:

    cd my-first-repo
    git pull
    git 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.

Original Repooctocat/Hello-Worldread-only for youForkYour Forkyou/Hello-Worldyou control thisCloneYour MachineHello-World/git push to forkopen PR from fork → original

Try it now

  1. Go to github.com/octocat/Hello-World.
  2. Click Fork (top-right) → Create fork.
  3. Clone your fork:
    git clone git@github.com:<username>/Hello-World.git
  4. Make a small change, commit, push to your fork.
  5. You would normally open a PR from your fork back to the original — you can try it if you like.

Summary

CommandWhat it does
git clone <url>Download a full copy of a remote repo
git fetchDownload remote changes, do not merge
git pullFetch and merge into current branch
Fork (GitHub UI)Copy someone else's repo to your account
Donate to this project