Skip to main content
The Remote Repository sequences teach you how to collaborate with others using Git. You’ll learn to push, pull, fetch, and synchronize your work with remote repositories.

Overview

Up until now, all your Git work has been local. Remote repositories enable collaboration by allowing you to share commits with others. These sequences cover both basic and advanced remote operations.
Learn Git Branching simulates remotes differently than real Git. Here, git clone creates a remote, rather than cloning from one. This helps visualize the relationship between local and remote repositories.

Push & Pull Sequence

The basic remote sequence covers fundamental remote operations.

1. Clone Intro

What you’ll learn: What remote repositories are and how to create them. Key concepts:
  • Remote repositories are copies of your repository on another computer
  • Remotes serve as backups and enable collaboration
  • Remote branches are prefixed with o/ (e.g., o/main)
  • git clone creates a remote repository (in this tutorial’s simulation)
Commands introduced:
git clone  # Create a remote repository
What happens:
  • A remote repository is created
  • Remote branches appear with o/ prefix
  • Local branches can track remote branches
In real Git, you clone FROM a remote repository. Here, we clone to CREATE a remote for learning purposes.

2. Remote Branches

What you’ll learn: How remote branches work and what they represent. Key concepts:
  • Remote branches reflect the state of the remote repository
  • They have special properties: detached HEAD when checked out
  • You can’t commit directly to remote branches
  • Remote branches update when you fetch, pull, or push
  • The o/ prefix indicates remote branches
Example:
# Local branch
main C3

# Remote branch (after clone)
o/main C1

# After pushing
main C3
o/main C3
Key properties:
  • Remote branches are read-only from your local perspective
  • They update automatically when syncing with the remote
  • They show where the remote repository was last time you synced

3. Git Fetch

What you’ll learn: How to download commits from the remote without merging. Key concepts:
  • git fetch downloads commits from the remote
  • It updates o/<branch> remote branches
  • Does NOT change your local branches
  • Does NOT change your working files
  • Safe operation that only downloads
Commands introduced:
git fetch  # Download commits from remote
What fetch does:
  1. Downloads new commits from the remote
  2. Updates remote branches (o/main, etc.)
  3. Leaves your local branches unchanged
  4. Allows you to review changes before integrating
Example:
# Before fetch
main C1
o/main C1

# Remote has new commits C2, C3
# After git fetch
main C1         (unchanged)
o/main C3       (updated)

4. Git Pull

What you’ll learn: How to download and merge remote changes. Key concepts:
  • git pull = git fetch + git merge
  • Downloads commits AND merges them into your branch
  • Updates both remote branches and your current branch
  • Creates merge commit if there are diverging changes
Commands introduced:
git pull  # Fetch and merge in one command
Example:
# Before pull
main C1
o/main C3 (remote is ahead)

# After git pull  
main C4 (merged with remote changes)
o/main C3
git pull is convenient but hides what’s happening. Use git fetch + git merge when you want more control.

5. Faking Teamwork

What you’ll learn: How to simulate remote changes for practice. Key concepts:
  • In Learn Git Branching, this simulates teammates pushing to remote
  • In real Git, others push to the shared remote
  • Helps you practice handling diverged branches
  • Prepares you for real collaboration scenarios
Commands introduced:
git fakeTeamwork <branch> <num>  # Simulate remote commits

6. Git Push

What you’ll learn: How to upload your commits to the remote. Key concepts:
  • git push uploads your commits to the remote
  • Updates the remote repository with your changes
  • Updates remote branches (o/main) to match
  • Can fail if remote has changes you don’t have (not “fast-forward”)
Commands introduced:
git push  # Upload commits to remote
Example:
# Before push
main C3
o/main C1

# After git push
main C3  
o/main C3  (updated)
Push can fail:
# If remote has commits you don't have
git push
# Error: Updates were rejected

# Solution: Pull first, then push
git pull
git push

7. Diverged Work (Fetch-Rebase Workflow)

What you’ll learn: How to handle diverged branches using rebase. Key concepts:
  • Your branch and remote branch can diverge
  • git pull --rebase = git fetch + git rebase
  • Creates cleaner, linear history compared to merge
  • Useful for keeping history tidy
Commands introduced:
git pull --rebase  # Fetch and rebase (instead of merge)
Rebase workflow:
# Diverged state
main C2 (your work)
o/main C3 (remote work)

# After git pull --rebase
main C2' (your work rebased on top)
o/main → C3

8. Locked Main (Push Rejection)

What you’ll learn: How to contribute when you can’t push to main directly. Key concepts:
  • Many teams lock the main branch
  • You must push to feature branches and create pull requests
  • Use git push origin <branch> to push to specific branches
  • Work on feature branches, not main directly
Example workflow:
# Create feature branch
git checkout -b feature
git commit

# Push feature branch
git push origin feature

# Pull request happens on GitHub/GitLab
# After merge, update local main
git checkout main  
git pull

Advanced Remote Operations

The Remote Advanced sequence covers complex remote scenarios.

1. Push Main (Multiple Branches)

What you’ll learn: Managing multiple local branches and pushing selectively. Key concepts:
  • Push only the branches you want to share
  • Can push multiple branches at once
  • Use specific push syntax for control

2. Merge Main (Multiple Features)

What you’ll learn: Combining multiple feature branches before pushing. Challenge: Merge several features into main, then push to remote.

3. Remote Tracking

What you’ll learn: How local branches track remote branches. Key concepts:
  • Local branches can track remote branches
  • Tracking enables git push and git pull without arguments
  • Set tracking with git checkout -b <branch> <remote>/<branch>
  • Or use git branch -u <remote>/<branch>
Commands:
git checkout -b feature o/feature  # Create and track
git branch -u o/main main          # Set tracking

4. Push Arguments

What you’ll learn: Specifying source and destination for push. Key concepts:
  • Full syntax: git push <remote> <source>:<destination>
  • Push local branch to different remote branch name
  • Can create new remote branches
Examples:
git push origin main             # Push main to origin/main
git push origin foo:main         # Push local foo to remote main
git push origin main:newBranch   # Create new remote branch

5. Push Arguments #2 (Creating Remote Branches)

What you’ll learn: Advanced push syntax for branch management.

6. Fetch Arguments

What you’ll learn: Specifying what to fetch and where to put it. Key concepts:
  • Full syntax: git fetch <remote> <source>:<destination>
  • Fetch specific branches
  • Download to different local branches
Examples:
git fetch origin main            # Fetch main
git fetch origin foo:bar         # Fetch foo to local bar

7. Source of Nothing

What you’ll learn: Using empty source to delete branches. Key concepts:
  • : with empty source deletes remote branches
  • git push origin :branch deletes remote branch
  • git fetch origin :branch deletes local branch
Examples:
git push origin :feature   # Delete remote feature branch
git fetch origin :local    # Delete local branch

8. Pull Arguments

What you’ll learn: Combining fetch and merge with precise control. Key concepts:
  • Pull arguments specify source and destination
  • Combines fetch arguments with merge behavior

Workflows Summary

Basic Workflow

git clone                  # Setup
git commit                 # Work locally  
git pull                   # Get remote changes
git push                   # Share your work

Rebase Workflow

git fetch                  # Download changes
git rebase origin/main     # Rebase on remote
git push                   # Share clean history

Feature Branch Workflow

git checkout -b feature    # Create feature branch
git commit                 # Work on feature
git push origin feature    # Push to remote
# Create pull request
git checkout main
git pull                   # Update main after merge

Key Commands Reference

CommandPurpose
git cloneCreate/setup remote repository
git fetchDownload commits (don’t merge)
git pullDownload and merge commits
git pushUpload commits to remote
git pull --rebaseDownload and rebase (not merge)
git push origin <branch>Push specific branch
git push <remote> <src>:<dest>Advanced push syntax
git fetch <remote> <src>:<dest>Advanced fetch syntax

Start Collaborating

Learn remote operations in the interactive tutorial

Build docs developers (and LLMs) love