Home·Terminal commands

git pull

git

Usage

git pull [--rebase|--ff-only] [<remote> <branch>]

Runs fetch and merge in one step, which is where surprise merge commits come from; --rebase or --ff-only prevents them.

Common flags

FlagMeaning
--rebasereplay your commits on top instead of merging
--ff-onlyrefuse if a merge commit would be needed
--no-rebasemerge, whatever pull.rebase says
--autostashpark local changes for the duration
--prunedrop tracking refs for deleted branches
--depth <n>shallow pull

Examples

git pull --rebase origin main

brings in server commits and puts yours on top

git pull --ff-only

updates only when nothing has to be merged

git pull --autostash

pulls even with uncommitted changes in the way

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git pull do?

Runs fetch and merge in one step, which is where surprise merge commits come from; --rebase or --ff-only prevents them.

Q. How do I type it?

git pull [--rebase|--ff-only] [<remote> <branch>] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-pull