What are Remote Repositories?
Remote repositories aren’t actually that complicated. They are simply copies of your repository on another computer. In today’s world of cloud computing, it’s easy to think there’s magic behind Git remotes, but they’re just repositories stored elsewhere.You typically communicate with remote repositories through the Internet, which allows you to transfer commits back and forth.
Why Use Remotes?
Remote repositories have powerful benefits:Backup
First and foremost, remotes serve as a great backup! If you lose all local data, you can still recover from the remote.
Collaboration
Remotes make coding social! Your friends can contribute to your project or pull your latest changes easily.
Distribution
Multiple people can work on the same project from different locations simultaneously.
History
Shared history lets everyone see the complete evolution of the project.
Remote Repositories in Learn Git Branching
Creating a Remote
In Learn Git Branching,git clone creates a remote repository from your local one:
This is opposite from real Git, where clone creates a local copy from a remote. But it helps you understand the relationship between local and remote repositories.
Visual Representation
After cloning, you’ll see:- Local repository (on the left)
- Remote repository labeled “origin” (on the right)
- Remote tracking branches prefixed with
o/(likeo/main)
Remote Tracking Branches
What are Remote Tracking Branches?
Remote tracking branches are local references that reflect the state of branches on the remote:o/ prefix indicates this is a remote tracking branch for the remote named “origin”.
Properties
- Read-only locally: You can’t commit directly to
o/main - Updated by network operations: Only
push,fetch, andpullmove them - Show remote state: They tell you what the remote looked like last time you synced
Special Characteristics
Fetching from Remote
What is Fetch?
Thegit fetch command downloads commits from the remote repository:
Update remote tracking branches
Your
o/main and other remote tracking branches update to match the remote.Fetch Example
Before fetch:git fetch:
maindidn’t move (still atC1)o/mainupdated toC3- New commits
C2andC3downloaded
Pushing to Remote
What is Push?
Thegit push command uploads your commits to the remote repository:
Push Example
Before push:git push:
Pulling from Remote
What is Pull?
Thegit pull command is essentially fetch + merge:
git pull = git fetch + git merge o/<branch>Pull Process
Pull Example
Before pull:git pull:
Pull with Rebase
Use--rebase for linear history:
fetch + rebase instead of fetch + merge.
The Git Pushin’ Level
The push introduction level teaches:Level Goal
Expected Result
Working with Remotes
The Origin Remote
By default, the remote is named “origin”:originis just a nickname- You could have multiple remotes
- Each remote has its own tracking branches
Remote Branch References
Reference remote branches with<remote>/<branch> syntax:
origin/mainoro/main- main branch on originorigin/featureoro/feature- feature branch on origin
Advanced Remote Concepts
Push.default Configuration
The behavior ofgit push without arguments depends on push.default setting:
upstream- Push current branch to its upstream (used in Learn Git Branching)simple- Push to same-named branch (default in modern Git)current- Always push to branch with same name
Remote Tracking
Branches can track remote branches:Divergent Histories
When Remote and Local Diverge
Problem:Solutions
Option 1: Pull then PushRemote Operations Implementation
From the source code:Common Remote Workflows
Solo Developer
Team Collaboration
Keeping Updated
Best Practices
Pull Before Push
Always fetch/pull before pushing to avoid conflicts.
Push Regularly
Push completed work frequently to back it up.
Fetch Often
Regularly fetch to see what teammates are doing.
Clean History
Clean up commits (rebase, squash) before pushing.
Remote Tracking Branch States
Ahead of Remote
Behind Remote
Diverged
In Sync
Common Remote Commands
View Remote Configuration
Fetch All Remotes
Push Specific Branch
Push New Branch
-u sets up tracking relationship.
Understanding the Visualization
Two Separate Trees
Learn Git Branching shows:- Left side: Your local repository
- Right side: The remote repository (origin)
- Connection: Remote tracking branches link them
Synchronization
Watch how operations affect both sides:- Commit: Only affects local
- Fetch: Updates local tracking branches
- Push: Updates both remote and tracking branches
- Pull: Fetches and merges into local
Remote Repository Platforms
While Learn Git Branching simulates remotes, real platforms include:- GitHub - Most popular Git hosting
- GitLab - Self-hosted or cloud
- Bitbucket - By Atlassian
- Custom servers - Self-hosted Git
These platforms add features like pull requests, issue tracking, and CI/CD on top of core Git functionality.
Related Concepts
- Branching - Creating branches locally and remotely
- Merging - Combining local and remote changes
- Rebasing - Alternative to merge for clean history
Next Steps
After understanding remote basics:- Practice fetch, pull, and push operations
- Learn to resolve divergent histories
- Understand push and pull with branches
- Explore advanced remote branch workflows
- Master pull requests and code review