Skip to main content

Synopsis

git pull [<options>] [<repository> [<refspec>...]]

Description

Integrate changes from a remote repository into the current branch. First, git pull runs git fetch with the same arguments (excluding merge options) to fetch remote branch(es). Then it decides which remote branch to integrate: if you run git pull with no arguments this defaults to the upstream for the current branch. Then it integrates that branch into the current branch. There are 4 main options for integrating the remote branch:
  1. git pull --ff-only will only do “fast-forward” updates: it fails if your local branch has diverged from the remote branch. This is the default.
  2. git pull --rebase runs git rebase
  3. git pull --no-rebase runs git merge
  4. git pull --squash runs git merge --squash
You can also set the configuration options pull.rebase, pull.squash, or pull.ff with your preferred behaviour.
If there’s a merge conflict during the merge or rebase that you don’t want to handle, you can safely abort it with git merge --abort or git rebase --abort.

Common Usage

1

Pull from the default remote

Update the remote-tracking branches for the repository you cloned from, then merge one of them into your current branch:
git pull
This is equivalent to git pull origin in most cases. Normally the branch merged in is the HEAD of the remote repository, but the choice is determined by the branch.<name>.remote and branch.<name>.merge options.
2

Pull a specific branch

Merge into the current branch the remote branch next:
git pull origin next
This leaves a copy of next temporarily in FETCH_HEAD, and updates the remote-tracking branch origin/next.
3

Recover from conflicts

If you tried a pull which resulted in complex conflicts and would want to start over, you can recover with:
git reset

Options

<repository>The “remote” repository to pull from. This can be either a URL or the name of a remote. Defaults to the configured upstream for the current branch, or origin.<refspec>Which branch or other reference(s) to fetch and integrate into the current branch, for example main in git pull origin main. Defaults to the configured upstream for the current branch. This can be a branch, tag, or other collection of reference(s).
-q, --quietThis is passed to both underlying git-fetch to squelch reporting of during transfer, and underlying git-merge to squelch output during merging.-v, --verbosePass --verbose to git-fetch and git-merge.
-r, --rebase[=(true|merges|false|interactive)]
  • true - rebase the current branch on top of the upstream branch after fetching. If there is a remote-tracking branch corresponding to the upstream branch and the upstream branch was rebased since last fetched, the rebase uses that information to avoid rebasing non-local changes. This is the default.
  • merges - rebase using git rebase --rebase-merges so that the local merge commits are included in the rebase
  • false - merge the upstream branch into the current branch
  • interactive - enable the interactive mode of rebase
This is a potentially dangerous mode of operation. It rewrites history, which does not bode well when you published that history already. Do not use this option unless you have read git-rebase carefully.
--no-rebaseThis is shorthand for --rebase=false.--squashRun git merge --squash to integrate changes.
--recurse-submodules[=(yes|on-demand|no)]--no-recurse-submodulesThis option controls if new commits of populated submodules should be fetched, and if the working trees of active submodules should be updated too.If the checkout is done via rebase, local submodule commits are rebased as well. If the update is done via merge, the submodule conflicts are resolved and checked out.

Examples

Basic pull from default remote

$ git pull
$ git pull origin
Normally the branch merged in is the HEAD of the remote repository, but the choice is determined by the branch.<name>.remote and branch.<name>.merge options.

Pull and merge a specific remote branch

$ git pull origin next
This leaves a copy of next temporarily in FETCH_HEAD, and updates the remote-tracking branch origin/next. The same can be done by invoking fetch and merge:
$ git fetch origin
$ git merge origin/next

Pull with rebase

$ git pull --rebase
This rebases the current branch on top of the upstream branch after fetching, instead of merging.

Default Behavior

Often people use git pull without giving any parameter. Traditionally, this has been equivalent to saying git pull origin. However, when configuration branch.<name>.remote is present while on branch <name>, that value is used instead of origin.

git fetch

Download objects and refs from another repository

git merge

Join two or more development histories together

git rebase

Reapply commits on top of another base tip

git config

Get and set repository or global options