Fetch, Pull, and Push
Remote Mechanics: Fetch, Pull, Push
After this page you can talk to another Git repository on Linux without confusing fetch with pull.
A remote is a named URL
cd ~/desk/desk-api
git remote add origin git@host:ada/desk-api.git
git remote -vorigin is a convention. The URL is SSH (chapter 2) or https://. For labs on one machine, a bare repo on disk is a valid remote:
~/desk/desk-api origin
working tree + .git (bare) objects + refs
│ git fetch origin/main ──► refs/heads/main
│ git push main ──────────► refs/heads/main
▼
refs/heads/main refs/remotes/origin/main
git init --bare ~/desk/desk-api.git
git remote add origin ~/desk/desk-api.gitfile:// and a path both work on Linux. Bare means no working tree — the shape a forge stores.
Fetch
git fetch origin
git fetch --all
git log --oneline --graph --decorate --allFetch downloads objects and updates remote-tracking names (origin/main). It does not move your main. Safe to run any time.
Push
git push -u origin main-u sets upstream so later git push and git pull know the default. After that:
git push
git status
# Your branch is up to date with 'origin/main'Push refuses if the remote has commits you do not. Fetch, integrate, push again.
Pull
git pullFetch plus integrate @{u} into HEAD. With pull.ff only (chapter 2), it fast-forwards or fails. git pull --rebase copies your local commits onto the updated upstream (chapter 9).
Prefer git fetch then look at git log --oneline main..origin/main before you integrate.
Tracking
git branch -vv
git rev-parse --abbrev-ref --symbolic-full-name '@{u}'@{u} is the upstream of the current branch. git push -u is how it gets set.
Delete a remote branch
git push origin --delete feat/ping-jsonLocal delete is still git branch -d. The two are independent.