Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Remotes and Collaboration

git pull command

Reference for git pull: fetch from a remote and merge or rebase into the current branch. Options --rebase, --ff-only, --no-commit, --autostash and pull.rebase.

git pull is git fetch followed by an integration step. It downloads new commits for the current branch's upstream and then either merges them into your branch (the default) or replays your local commits on top of them (--rebase).

Because the second step changes your branch and working tree, pull can stop with conflicts. If you want to look before you leap, run git fetch and then merge or rebase by hand. Since Git 2.27 the command warns when you have not told it how to reconcile diverged history, and you should set pull.rebase or pull.ff once.

Terminal
git pull [<options>] [<remote> [<refspec>...]]
git pull --rebase | --ff-only | --no-rebase

Try it

Bash Fast-forward pull

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Diverged history: merge, rebase or refuse

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

<remote> and <refspec> are the same as for fetch. With no arguments Git pulls from the upstream configured for the current branch (branch.<name>.remote and branch.<name>.merge); if there is none, it stops and tells you how to set it.

Option Description
--rebase[=true|false|merges|interactive], -r Rebase local commits onto the fetched tip instead of merging. merges keeps merge commits.
--no-rebase Merge, overriding pull.rebase.
--ff-only Succeed only when the branch can fast-forward; otherwise fail without changing anything.
--ff, --no-ff Allow a fast-forward (default) or always create a merge commit.
--no-commit, --commit Stop before committing a merge, or commit as usual.
--autostash Stash local changes before the integration and reapply them afterwards.
-s <strategy>, -X <option> Merge strategy and strategy options; see merge strategies.
--squash Produce the result of the merge as staged changes without a commit or merge.
--verify-signatures Refuse to merge a tip without a valid GPG signature.
--stat, -n Show or hide the diffstat after the merge.
-q, -v Quiet or verbose.
Any git fetch option --all, --prune, --tags, --depth and so on are passed through.

Config: pull.rebase (true, false, merges, interactive), pull.ff (only makes every pull fast-forward only), branch.<name>.rebase for one branch, rebase.autoStash and merge.autoStash.

Usage notes

  • On diverged history without any configuration, Git 2.33 and later refuses with "Need to specify how to reconcile divergent branches" instead of silently creating a merge commit. Choose with git config pull.rebase false|true or pull.ff only.
  • --ff-only is the safest default for scripts and shared branches: pull never makes an unexpected merge commit.
  • Rebasing rewrites your unpublished local commits. If you already pushed them, use merge instead, or you will need a force push.
  • A dirty working tree is fine for a fast-forward when the incoming changes do not touch the same files; otherwise Git stops. --autostash makes dirty trees work with rebase.
  • git pull --rebase after a conflict leaves you inside a rebase: fix files, git add, then git rebase --continue (or --abort).
  • git pull origin topic merges origin/topic into your current branch, whatever it is named.
  • If you only want to update tracking refs, use git fetch.