Beginner · 5 min read
fetch, pull, push: talking to the remote
Your repository and GitHub's are two different copies. Here is how they stay in sync.
fetch: look without touching
Downloads new commits into origin/* branches but never changes your own branches or files. Always safe, run it as often as you like.
Safe
$ git fetch origin$ git log --oneline HEAD..origin/main
pull: fetch + integrate
pull is fetch followed by a merge (or a rebase with --rebase). That's where conflicts can appear. Pull before starting work and before pushing.
Safe
$ git pull --rebase
push: publish your commits
push sends your commits to the remote. If someone pushed before you, it is rejected: pull, then push again. Never force your way through on a shared branch.
Safe
$ git push -u origin HEAD