SteelReed

Search

Search posts, questions…

DevOps & CloudQuestion 2 / 35

Junior

How do git clone, fetch, pull and pull --rebase differ?

Short answer

clone creates a local repo from a remote, once. fetch only downloads and updates origin/main, not touching your branch or edited files. pull = fetch + merge; pull --rebase = fetch + rebase, giving a straight history.

git clone, first timegit fetchmerge: pullrebase: pull --rebaseRemoteLocal repoorigin/main updatedyour branch untouchedmain gets merge commitLocal commits replayedon top, straight history

3 points to say:

  1. fetch is always safe: it only updates remote-tracking branches; inspect with git log HEAD..origin/main before integrating.
  2. pull = fetch + merge, pull --rebase = fetch + rebase (no extra merge commit).
  3. Set pull.rebase true for personal branches; rebase rewrites unpushed local commits, never rebase commits others build on.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.