Search code examples
gitgit-pull

What modes does git pull have other than the default?


The git-pull section of the Pro Git book says "In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD."

What other modes are there, and where can I find documentation for them?


Solution

  • The other modes are described in the documentation you linked.

    The word mode is not very well defined, so it means different things to different people. Probably the primary item is somewhat well disguised here, about 1/4 of the way down the page:

    -r
    --rebase[=false|true|merges|preserve|interactive]

    When 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.

    When set to merges, rebase using git rebase --rebase-merges so that the local merge commits are included in the rebase (see git-rebase[1] for details).

    When set to preserve, rebase with the --preserve-merges option passed to git rebase so that locally created merge commits will not be flattened.

    When false, merge the current branch into the upstream branch.

    When interactive, enable the interactive mode of rebase.

    See pull.rebase, branch.<name>.rebase and branch.autoSetupRebase in git-config[1] if you want to make git pull always use --rebase instead of merging.

      Note
      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[1]] carefully.

    However, other "modes" may include running git pull with arguments, such as git pull upstream branch-X. This runs git fetch upstream branch-X followed by running git merge FETCH_HEAD, so to me that seems like the same "mode".

    Personally, I recommend not using git pull at all. Run git fetch, then run your own second command. I find, for instance, that I often want to run git log between the two commands, and using git pull makes that impossible. I may choose git merge, or git rebase, or neither, after seeing what git fetch fetched.