World map

 

BM: Baca dalam Bahasa Melayu

World 4: Hello GitHub

Fetch vs pull

You will learn: how to get your team's new commits, and peek before you join them in.

The problem

Aisyah's parcel lands on GitHub. GitHub now has her new commit. Your laptop still shows the old picture.

Your laptop~/diary
  1. ea2c020Add purple stylemain (HEAD is here)origin/main
  2. f6c78e5Add home page
  3. 2efd0f2Add README
0 ahead · 0 behind origin/main
GitHubgithub.com/you/diary
  1. ea2c020Add purple stylemain
  2. f6c78e5Add home page
  3. 2efd0f2Add README

Aisyah just pushed her diary entry. Your laptop has no idea. How do you find out?

Watch

git fetch downloads main to origin/main. git status says your branch is behind origin/main by 1 commit. Terminal output: $ git fetch From https://github.com/you/diary ea2c020..c64aa8e main -> origin/main $ git status On branch main Your branch is behind 'origin/main' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) nothing to commit, working tree clean

fetch: Download news from a remote. Your own branches and files stay the same. downloads the news. It moves origin/main only. Your own main and your files stay put.

Try it

Fetch first and look at your laptop. Then pull Aisyah’s entry into main.

Your laptop~/diary
  1. ea2c020Add purple stylemain (HEAD is here)origin/main
  2. f6c78e5Add home page
  3. 2efd0f2Add README
0 ahead · 0 behind origin/main
GitHubgithub.com/you/diary
  1. c64aa8eAdd Aisyah's day 2 · Aisyah (only on GitHub)main
  2. ea2c020Add purple style
  3. f6c78e5Add home page
  4. 2efd0f2Add README

Tap an action. Watch the courier.

Predict

You ran git fetch. Did your index.html change?

Pick one answer.

Watch

After git fetch, a purple commit appears with the origin/main label on it. The main label stays one commit behind.
2efd0f2f6c78e5ea2c020

origin/main is a remote-tracking branch: Your laptop's memory of a remote branch, like origin/main. It moves when you fetch.. It is your laptop’s memory of GitHub. It moves only when you fetch, pull or push.

Check

Fetch or pull? Sort each one.

Drag a card into a box. Or tap the card, then tap the box.

      Try it

      Type it yourself: fetch, look with git status, then pull.

      2efd0f2f6c78e5ea2c020

      You did it!

      You can now fetch to peek and pull to catch up.

      Go deeper (optional)

      git pull is git fetch plus a merge (or a rebase: next lesson). After a fetch, git log --oneline main..origin/main lists what is new. git fetch --prune forgets remote branches that were deleted on GitHub.