push, pull & fetch
Syncing with the Remote
| Command | Direction | Does |
|---|---|---|
git push | local → remote | Upload your commits |
git fetch | remote → local | Download commits, don't merge |
git pull | remote → local | Fetch and merge into your branch |
$ git push origin main
$ git pull # = git fetch + git merge
Analogy:fetchis checking the mailbox (you see what arrived).pullis checking the mailbox and filing everything into your drawers (fetch + merge).pushis mailing your letters out.
Warning: git pull can trigger a merge conflict if the remote changed lines you also changed. Commit or stash your work before pulling so you're never merging on top of a messy tree.
First push of a new branch needs the upstream set:
$ git push -u origin feature-login # -u links local ↔ remote branch
$ git push # afterwards, just this