Course contentsShow
← Computer Science
Lesson 2192 of 2,87249. Version Control with GitFree lesson

Remote Branches

Understand how remote-tracking branches work and how to fetch, pull, and push branches between repositories.

Remote Branches

You'll learn how remote-tracking branches let you synchronize work between your local repository and remote servers.

What Are Remote Branches?

Remote branches are references to the state of branches in remote repositories (like GitHub or GitLab). When you clone a repository, Git creates remote-tracking branches—local snapshots that reflect what existed on the remote server at the time of your last sync. These branches have names like origin/main or origin/feature-login.

Think of remote branches like weather station readings: you have a local copy showing what the remote looked like last time you checked, but the actual remote may have changed since then.

How They Work

When you clone a repository, Git automatically:

  • Creates a remote named origin pointing to the source
  • Creates remote-tracking branches (read-only references)
  • Checks out a local branch to work on

You interact with remote branches using:

  • git fetch: Downloads new data from the remote and updates your remote-tracking branches (origin/main etc.), but doesn't modify your local branches
  • git pull: Fetches and merges the remote branch into your current local branch (essentially fetch + merge)
  • git push: Uploads your local branch commits to the remote repository

The Workflow

  1. You commit locally on main
  2. Someone else pushes to origin/main
  3. git fetch updates your origin/main reference
  4. Your local main and origin/main now diverge
  5. git merge origin/main or git pull integrates their changes
  6. git push shares your merged work back

Key Takeaway: Remote-tracking branches are local bookmarks showing remote repository state; use fetch to update them, pull to fetch and merge, and push to share your changes.