Back to roadmap

Lesson 10

Fetch

Fetch downloads remote history so you can inspect it without changing your current branch.

Visual Explanation

Ready to run git fetch --prune origin.

Keep These Ideas

Download only
Your files and local main branch do not move.
origin/main
Your local Git's latest known position for main on origin.
Inspect first
Compare incoming commits before deciding how to integrate them.

The Real Command

Terminal
git fetch --prune origin
Example Output
From https://gitlab.com/acme/shop
   a1b2c3d..d4e5f6a  main     -> origin/main
 - [deleted]         (none)   -> origin/old-demo

git fetch downloads origin's latest history. --prune also removes local labels for remote branches that no longer exist.

Command Details

git fetch origin

Fetch one remote. It updates remote-tracking labels such as origin/main.

Example Output
From https://gitlab.com/acme/shop
   a1b2c3d..d4e5f6a  main -> origin/main
git log main..origin/main --oneline

Two dots compare endpoints. This lists commits origin/main has that local main does not.

Example Output
d4e5f6a Add login validation
b2c3d4e Build login form

Knowledge Check

Inspect Remote Work Safely

Download updated remote knowledge without changing your current branch.

Question 1 of 5

  1. Question 1: current
  2. Question 2: not started
  3. Question 3: not started
  4. Question 4: not started
  5. Question 5: not started
Command Challenge

Download updates from origin and clean up remote-tracking names that origin deleted.