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 clonecreates a remote repository (in this tutorial’s simulation)
- A remote repository is created
- Remote branches appear with
o/prefix - Local branches can track remote branches
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
- 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 fetchdownloads 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
- Downloads new commits from the remote
- Updates remote branches (
o/main, etc.) - Leaves your local branches unchanged
- Allows you to review changes before integrating
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
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
6. Git Push
What you’ll learn: How to upload your commits to the remote. Key concepts:git pushuploads 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”)
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
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
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 pushandgit pullwithout arguments - Set tracking with
git checkout -b <branch> <remote>/<branch> - Or use
git branch -u <remote>/<branch>
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
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
7. Source of Nothing
What you’ll learn: Using empty source to delete branches. Key concepts::with empty source deletes remote branchesgit push origin :branchdeletes remote branchgit fetch origin :branchdeletes 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
Rebase Workflow
Feature Branch Workflow
Key Commands Reference
| Command | Purpose |
|---|---|
git clone | Create/setup remote repository |
git fetch | Download commits (don’t merge) |
git pull | Download and merge commits |
git push | Upload commits to remote |
git pull --rebase | Download 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