Skip to main content

Remotes, Fetch, Pull, and Push

What This Concept Is​

A remote is another repository Git knows how to talk to. Remote-tracking branches such as origin/main record the last known state of remote branches. fetch, pull, and push are synchronization commands, but they do different jobs.

Core distinctions:

  • fetch: download remote data and update remote-tracking references
  • pull: fetch, then integrate into current branch
  • push: publish local commits to a remote branch

Why It Matters Here​

Many Git mistakes come from using pull as a habit instead of as a deliberate integration command. If you understand remote-tracking branches, you can inspect remote state first and choose how to integrate it.

Concrete Example​

Explicit update sequence after confirming a clean working tree and switching to the intended local main branch:

git switch main
git fetch origin
git branch -vv
git log --oneline --graph --decorate --all -8
git merge origin/main

That sequence is often clearer than git pull because you can inspect before integrating.

Publishing a topic branch:

git push -u origin feature/login

The -u sets upstream tracking for the successfully pushed branch. Default push behavior also depends on configuration; keep the remote and branch explicit in this module. See the local collaboration lab.

Common Confusion / Misconception​

Misconception: origin/main is "the real branch on the server."

Correction: origin/main is a local reference that Git updates when you communicate with the server.

Misconception: pull only downloads changes.

Correction: pull downloads and then integrates. That second step is the risky one if you have not inspected state first.

How To Use It​

Prefer this default rhythm when the situation is unclear:

  1. git fetch
  2. inspect with git branch -vv and git log --graph
  3. choose merge or rebase intentionally
  4. git push only after local state is correct

Check Yourself​

  1. What changes locally after git fetch?
  2. Why might git fetch be safer than git pull as a default habit?
  3. What does git push -u origin feature-x configure?

Mini Drill or Application​

Use one bare repository and two working clones:

  1. make a commit in clone A and push it
  2. in clone B, run git fetch
  3. inspect origin/main before integrating
  4. integrate the change with merge or rebase
  5. create a new local branch in clone B and push it with -u
  6. verify tracking with git branch -vv

Read This Only If Stuck​