Script Valley
Git and GitHub Complete Course: From Beginner to Advanced
Working with GitHub: Remotes, Push, Pull, and CollaborationLesson 3.2

Fetching, Pulling, and Pushing Changes

git fetch, git pull, git push, remote tracking branches, origin/main, upstream tracking

Fetching, Pulling, and Pushing Changes

When working with remote repositories, three commands manage synchronization: git fetch, git pull, and git push. Understanding the difference between them is essential for avoiding conflicts.

Diagramgit fetch vs git pull vs git push

IMAGE PROMPT (replace this block with your generated image):

Flat three-column command anatomy diagram on white background. Title: fetch vs pull vs push — What Each Does. Three equal-width cards side by side. Card 1: git fetch (header fill: gray #f0f0f0). Body: arrow from Remote to a box labeled origin/main (remote tracking branch). Local main branch NOT moved. Label: Downloads changes, does NOT merge. Safe to run anytime. Card 2: git pull (header fill: light #3A5EFF #e8ecff). Body: = git fetch + git merge shown as two sequential mini-arrows. Local main branch moves forward. Label: Downloads AND merges into current branch. Variant badge: git pull --rebase. Card 3: git push (header fill: solid #3A5EFF, white text). Body: arrow from Local main to Remote origin/main. Label: Uploads local commits to remote. Rejected if remote is ahead. Fix badge: pull first, resolve, then push. White background, rounded card corners, monospace for commands.

git fetch

git fetch origin downloads all new commits and branches from the remote but does not modify your local branches. It updates remote tracking branches like origin/main. Use fetch to see what others have done without affecting your work:

git fetch origin
git log origin/main --oneline

git pull

git pull is essentially git fetch followed by git merge. It downloads remote changes and immediately merges them into your current branch. If you prefer rebase-style integration, use:

git pull --rebase origin main

git push

Push your local commits to the remote:

git push origin main

If someone else pushed while you were working, your push will be rejected. You must first pull their changes, resolve any conflicts, and then push again.

Remote Tracking Branches

Remote tracking branches like origin/main are local read-only references to the state of remote branches at last fetch. They help you compare your work with the remote without being online.

Up next

Forking and Contributing to Open Source

Sign in to track progress