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
originpointing 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/mainetc.), but doesn't modify your local branchesgit pull: Fetches and merges the remote branch into your current local branch (essentiallyfetch+merge)git push: Uploads your local branch commits to the remote repository
The Workflow
- You commit locally on
main - Someone else pushes to
origin/main git fetchupdates yourorigin/mainreference- Your local
mainandorigin/mainnow diverge git merge origin/mainorgit pullintegrates their changesgit pushshares 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.