Skip to content

Lesson

Remotes

Local vs remote, remote-tracking branches, and fetch, pull, and push.

Intermediate 7 min read

Learning objectives

  • Distinguish local, remote, and remote-tracking branches
  • Explain fetch vs pull
  • Understand ahead/behind

Remotes and tracking

A remote (usually origin) is a copy of the repository elsewhere. origin/main is a remote-tracking branch: your local record of where main was on the remote at the last fetch.

Fetch vs pull

git fetch downloads new commits and updates origin/… without touching your branches. git pull does a fetch and then integrates the changes into your current branch.

Ahead and behind

Your local main can be ahead of origin/main (you have unpushed commits), behind (there are unpulled commits), or both (diverged), which requires a merge or rebase.

Try it yourself

interactive visualization

Empty folder

Run git init to create a repository.

Working directory

Clean — no uncommitted changes.

git add ↓

Staging area

Nothing staged. Run git add.

git commit ↓

Repository

No commits yet.

1/4Empty repositoryOpen in visualizer

Push to create origin/main, then fetch and pull to sync.

Commands used

terminal
git push -u origin main
git fetch
git pull

Common mistakes

  • Assuming fetch updates your branch.
  • Pulling with conflicting local changes.

Best practices

  • Pull before starting new work.
  • Push focused branches, not everything at once.

Mini challenge

Explain why origin/main and local main can point at different commits.

Open the visualizer to try it

Summary

  • origin/main is a tracking branch.
  • fetch is safe; pull integrates.
  • Branches can be ahead or behind.
Next lessonPull requests