Lesson
Remotes
Local vs remote, remote-tracking branches, and fetch, pull, and push.
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
Empty folder
Run git init to create a repository.
Working directory
Clean — no uncommitted changes.
Staging area
Nothing staged. Run git add.
Repository
No commits yet.
Push to create origin/main, then fetch and pull to sync.
Commands used
git push -u origin main
git fetch
git pullCommon 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 itSummary
- origin/main is a tracking branch.
- fetch is safe; pull integrates.
- Branches can be ahead or behind.