git-pull.txt 5.3 KB
Newer Older
J
Junio C Hamano 已提交
1 2
git-pull(1)
===========
3 4 5

NAME
----
6
git-pull - Fetch from and merge with another repository or a local branch
7 8 9 10


SYNOPSIS
--------
11
'git-pull' <options> <repository> <refspec>...
12

13 14 15

DESCRIPTION
-----------
16 17
Runs `git-fetch` with the given parameters, and calls `git-merge`
to merge the retrieved head(s) into the current branch.
18

19
Note that you can use `.` (current directory) as the
20 21
<repository> to pull from the local repository -- this is useful
when merging local branches into the current branch.
22

23

24 25
OPTIONS
-------
26
include::merge-options.txt[]
27

28
:git-pull: 1
29
include::fetch-options.txt[]
30

31
include::pull-fetch-param.txt[]
32

33
include::urls-remotes.txt[]
34

35
include::merge-strategies.txt[]
36

37 38 39 40 41
\--rebase::
	Instead of a merge, perform a rebase after fetching.
	*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
42
	unless you have read linkgit:git-rebase[1] carefully.
43 44 45 46

\--no-rebase::
	Override earlier \--rebase.

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
DEFAULT BEHAVIOUR
-----------------

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

In order to determine what URL to use to fetch from, the value
of the configuration `remote.<origin>.url` is consulted
and if there is not any such variable, the value on `URL: ` line
in `$GIT_DIR/remotes/<origin>` file is used.

In order to determine what remote branches to fetch (and
optionally store in the tracking branches) when the command is
run without any refspec parameters on the command line, values
of the configuration variable `remote.<origin>.fetch` are
consulted, and if there aren't any, `$GIT_DIR/remotes/<origin>`
file is consulted and its `Pull: ` lines are used.
In addition to the refspec formats described in the OPTIONS
section, you can have a globbing refspec that looks like this:

------------
refs/heads/*:refs/remotes/origin/*
------------

A globbing refspec must have a non-empty RHS (i.e. must store
what were fetched in tracking branches), and its LHS and RHS
must end with `/*`.  The above specifies that all remote
branches are tracked using tracking branches in
`refs/remotes/origin/` hierarchy under the same name.

The rule to determine which remote branch to merge after
fetching is a bit involved, in order not to break backward
compatibility.

If explicit refspecs were given on the command
line of `git pull`, they are all merged.

When no refspec was given on the command line, then `git pull`
uses the refspec from the configuration or
`$GIT_DIR/remotes/<origin>`.  In such cases, the following
rules apply:

. If `branch.<name>.merge` configuration for the current
  branch `<name>` exists, that is the name of the branch at the
  remote site that is merged.

. If the refspec is a globbing one, nothing is merged.

. Otherwise the remote branch of the first refspec is merged.


101 102 103 104
EXAMPLES
--------

git pull, git pull origin::
105 106 107 108 109
	Update the remote-tracking branches for the repository
	you cloned from, then merge one of them into your
	current branch.  Normally the branch merged in is
	the HEAD of the remote repository, but the choice is
	determined by the branch.<name>.remote and
110
	branch.<name>.merge options; see linkgit:git-config[1]
111 112 113 114 115 116
	for details.

git pull origin next::
	Merge into the current branch the remote branch `next`;
	leaves a copy of `next` temporarily in FETCH_HEAD, but
	does not update any remote-tracking branches.
117 118 119

git pull . fixes enhancements::
	Bundle local branch `fixes` and `enhancements` on top of
N
Nicolas Pitre 已提交
120 121
	the current branch, making an Octopus merge.  This `git pull .`
	syntax is equivalent to `git merge`.
122

123 124 125 126
git pull -s ours . obsolete::
	Merge local branch `obsolete` into the current branch,
	using `ours` merge strategy.

127 128 129 130 131 132 133 134 135 136
git pull --no-commit . maint::
	Merge local branch `maint` into the current branch, but
	do not make a commit automatically.  This can be used
	when you want to include further changes to the merge,
	or want to write your own merge commit message.
+
You should refrain from abusing this option to sneak substantial
changes into a merge commit.  Small fixups like bumping
release/version name would be acceptable.

137 138 139 140
Command line pull of multiple branches from one repository::
+
------------------------------------------------
$ git checkout master
141 142
$ git fetch origin +pu:pu maint:tmp
$ git pull . tmp
143 144
------------------------------------------------
+
145 146 147
This updates (or creates, as necessary) branches `pu` and `tmp`
in the local repository by fetching from the branches
(respectively) `pu` and `maint` from the remote repository.
148
+
149 150
The `pu` branch will be updated even if it is does not
fast-forward; the others will not be.
151
+
152
The final command then merges the newly fetched `tmp` into master.
153

154

J
Junio C Hamano 已提交
155 156
If you tried a pull which resulted in a complex conflicts and
would want to start over, you can recover with
157
linkgit:git-reset[1].
J
Junio C Hamano 已提交
158 159


160 161
SEE ALSO
--------
162
linkgit:git-fetch[1], linkgit:git-merge[1], linkgit:git-config[1]
163 164


165 166
Author
------
J
Junio C Hamano 已提交
167 168
Written by Linus Torvalds <torvalds@osdl.org>
and Junio C Hamano <junkio@cox.net>
169 170 171

Documentation
--------------
172 173 174
Documentation by Jon Loeliger,
David Greaves,
Junio C Hamano and the git-list <git@vger.kernel.org>.
175 176 177

GIT
---
178
Part of the linkgit:git[7] suite