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.

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

Fetching, Pulling, and Pushing Changes โ€” Working with GitHub: Remotes, Push, Pull, and Collaboration โ€” Git and GitHub Complete Course: From Beginner to Advanced โ€” Script Valley โ€” Script Valley