foundation
Remote
Synchronize local repository history with shared servers through fetch, pull, push, and remote-tracking branches.
A remote is a named URL (or path) to another repository — `origin` is conventional. **Fetch** downloads objects and updates remote-tracking refs without changing your current branch. **Pull** is fetch plus integration (merge or rebase per config). **Push** publishes local commits.
git remote -v
git fetch origin
git pull --rebase origin main
git push -u origin feature/login
Upstream tracking (`branch.main.remote`) links local branches to remote counterparts. Push rejection usually means someone else advanced the remote — fetch, integrate, then push.
On interviews: origin vs upstream, tracking branches, fetch vs pull, and why non-fast-forward push rejection protects shared history.
Common pitfalls: `git pull` without knowing merge vs rebase default; pushing to protected branches; force-push overwriting teammates' work.
The trade-off is convenience (`git pull`) versus explicit control (fetch + rebase/merge separately).
Checklist:
- Fetch before comparing to remote state.
- Understand tracking branch configuration.
- Use protected branches for shared integration refs.
- Configure pull behavior explicitly per team policy.