Skip to main content

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:
git clone
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/ (like o/main)

Remote Tracking Branches

What are Remote Tracking Branches?

Remote tracking branches are local references that reflect the state of branches on the remote:
main --> C3        (local branch)
o/main --> C3      (remote tracking branch)
The 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, and pull move them
  • Show remote state: They tell you what the remote looked like last time you synced

Special Characteristics

Remote tracking branches are in a special “detached HEAD” state. You can view them but shouldn’t make commits directly on them.

Fetching from Remote

What is Fetch?

The git fetch command downloads commits from the remote repository:
git fetch
1

Download commits

Fetch downloads new commits from the remote that you don’t have locally.
2

Update remote tracking branches

Your o/main and other remote tracking branches update to match the remote.
3

Don't change local branches

Your local branches (main, etc.) stay exactly where they were.

Fetch Example

Before fetch:
Local:                  Remote (origin):
main --> C1             main --> C3
o/main --> C1           |
                        C2
                        |
                        C1
After git fetch:
Local:                  Remote (origin):
main --> C1             main --> C3
o/main --> C3           |
C3                      C2
|
                        C1
C2
|
C1
Notice:
  • main didn’t move (still at C1)
  • o/main updated to C3
  • New commits C2 and C3 downloaded

Pushing to Remote

What is Push?

The git push command uploads your commits to the remote repository:
git push
1

Upload commits

Push uploads commits from your local branch that the remote doesn’t have.
2

Update remote branch

The remote branch (like main on origin) moves to include your commits.
3

Update remote tracking branch

Your local o/main updates to match the new remote state.

Push Example

Before push:
Local:                  Remote (origin):
main --> C3             main --> C1
|
o/main --> C1           C1
C2                      |
|                       C0
C1
|
C0
After git push:
Local:                  Remote (origin):
main --> C3             main --> C3
|
                        |
o/main --> C3           C2
C2                      |
|                       C1
C1                      |
|                       C0
C0
Everything synchronized!

Pulling from Remote

What is Pull?

The git pull command is essentially fetch + merge:
git pull
git pull = git fetch + git merge o/<branch>

Pull Process

1

Fetch

Download new commits from remote, update o/main.
2

Merge

Merge the remote tracking branch into your current branch.

Pull Example

Before pull:
main* --> C1
o/main --> C3
After git pull:
main* --> C4 (merge commit)
         /  \
       C1    C3
o/main --> C3

Pull with Rebase

Use --rebase for linear history:
git pull --rebase
This does fetch + rebase instead of fetch + merge.

The Git Pushin’ Level

The push introduction level teaches:

Level Goal

1

Clone repository

git clone
Creates the remote and tracking branches.
2

Create local commits

git commit
git commit
Creates C2 and C3 locally.
3

Push to remote

git push
Uploads commits, updates remote and o/main.

Expected Result

Local and Remote both at:
main --> C3
  |
  C2
  |
  C1

Working with Remotes

The Origin Remote

By default, the remote is named “origin”:
  • origin is 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/main or o/main - main branch on origin
  • origin/feature or o/feature - feature branch on origin

Advanced Remote Concepts

Push.default Configuration

The behavior of git 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:
{
  id: "main",
  target: "C3",
  remoteTrackingBranchID: "o/main"  // Tracks this remote branch
}
This tells Git where to push/pull by default.

Divergent Histories

When Remote and Local Diverge

Problem:
Local:                  Remote:
main --> C2             main --> C3
  |                       |
  C1                      C1
Both have changes the other doesn’t have.

Solutions

Option 1: Pull then Push
git pull     # Merge remote changes
git push     # Push combined result
Option 2: Pull with Rebase
git pull --rebase  # Rebase local changes
git push          # Push rebased commits
Option 3: Force Push (dangerous!)
git push --force  # Overwrite remote (use with caution)
Force pushing overwrites remote history. Only use on branches you own and when you understand the consequences.

Remote Operations Implementation

From the source code:
// Creates origin tree structure
originTree: {
  branches: {
    main: { target: "C1" }
  },
  commits: { ... },
  HEAD: { target: "main" }
}

Common Remote Workflows

Solo Developer

1. Clone repository
2. Make changes and commit
3. Push to remote (backup)
4. Repeat

Team Collaboration

1. Fetch latest changes
2. Create feature branch
3. Develop and commit
4. Push feature branch
5. Create pull request
6. Merge when reviewed

Keeping Updated

Regularly:
- git fetch    (see what's new)
- git pull     (integrate changes)
- git push     (share your work)

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

main --> C2
o/main --> C1
You have commits to push.

Behind Remote

main --> C1
o/main --> C2  
You need to pull.

Diverged

main --> C2
o/main --> C3
         \
          C1 (common ancestor)
Both local and remote have unique commits.

In Sync

main --> C2
o/main --> C2
Perfectly synchronized.

Common Remote Commands

View Remote Configuration

git remote -v
Shows configured remotes (not in Learn Git Branching).

Fetch All Remotes

git fetch --all
Fetches from all configured remotes.

Push Specific Branch

git push origin feature-branch
Pushes specific branch to remote.

Push New Branch

git push -u origin new-branch
The -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.
  • 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:
  1. Practice fetch, pull, and push operations
  2. Learn to resolve divergent histories
  3. Understand push and pull with branches
  4. Explore advanced remote branch workflows
  5. Master pull requests and code review

Build docs developers (and LLMs) love