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 referencespull: fetch, then integrate into current branchpush: 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
Safer update sequence:
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 the upstream so future pulls and pushes know which remote branch this local branch tracks.
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:
git fetch- inspect with
git branch -vvandgit log --graph - choose merge or rebase intentionally
git pushonly after local state is correct
Check Yourself
- What changes locally after
git fetch? - Why might
git fetchbe safer thangit pullas a default habit? - What does
git push -u origin feature-xconfigure?
Mini Drill or Application
Use one bare repository and two working clones:
- make a commit in clone A and push it
- in clone B, run
git fetch - inspect
origin/mainbefore integrating - integrate the change with merge or rebase
- create a new local branch in clone B and push it with
-u - verify tracking with
git branch -vv