3 # Copyright (c) 2005 Junio C Hamano
5 # Fetch one or more remote refs and merge it/them into the current HEAD.
11 git pull [options] [<repository> [<refspec>...]]
13 Fetch one or more remote refs and integrate it/them with the current HEAD.
15 v,verbose be more verbose
17 progress force progress reporting
19 Options related to merging
20 r,rebase?false|true|preserve incorporate changes by rebasing rather than merging
21 n! do not show a diffstat at the end of the merge
22 stat show a diffstat at the end of the merge
23 summary (synonym to --stat)
24 log?n add (at most <n>) entries from shortlog to merge commit message
25 squash create a single commit instead of doing a merge
26 commit perform a commit if the merge succeeds (default)
27 e,edit edit message before committing
29 ff-only! abort if fast-forward is not possible
30 verify-signatures verify that the named commit has a valid GPG signature
31 s,strategy=strategy merge strategy to use
32 X,strategy-option=option option for selected merge strategy
33 S,gpg-sign?key-id GPG sign commit
35 Options related to fetching
36 all fetch from all remotes
37 a,append append to .git/FETCH_HEAD instead of overwriting
38 upload-pack=path path to upload pack on remote end
39 f,force force overwrite of local branch
40 t,tags fetch all tags and associated objects
41 p,prune prune remote-tracking branches no longer on remote
42 recurse-submodules?on-demand control recursive fetching of submodules
44 k,keep keep downloaded pack
45 depth=depth deepen history of shallow clone
46 unshallow convert to a complete repository
47 update-shallow accept refs that update .git/shallow
48 refmap=refmap specify fetch refmap
50 test $# -gt 0 && args
="$*"
53 set_reflog_action
"pull${args+ $args}"
54 require_work_tree_exists
59 git diff-index
--cached --name-status -r --ignore-submodules HEAD
--
60 if [ $
(git config
--bool --get advice.resolveConflict ||
echo true
) = "true" ]; then
61 die
"$(gettext "Pull is not possible because you have unmerged files.
62 Please
, fix them up
in the work tree
, and
then use
'git add/rm <file>'
63 as appropriate to mark resolution and
make a commit.
")"
65 die
"$(gettext "Pull is not possible because you have unmerged files.
")"
70 if [ $
(git config
--bool --get advice.resolveConflict ||
echo true
) = "true" ]; then
71 die
"$(gettext "You have not concluded your merge
(MERGE_HEAD exists
).
72 Please
, commit your changes before merging.
")"
74 die
"$(gettext "You have not concluded your merge
(MERGE_HEAD exists
).
")"
78 test -z "$(git ls-files -u)" || die_conflict
79 test -f "$GIT_DIR/MERGE_HEAD" && die_merge
81 bool_or_string_config
() {
82 git config
--bool "$1" 2>/dev
/null || git config
"$1"
85 strategy_args
= diffstat
= no_commit
= squash
= no_ff
= ff_only
=
86 log_arg
= verbosity
= progress
= recurse_submodules
= verify_signatures
=
87 merge_args
= edit
= rebase_args
= all
= append
= upload_pack
= force
= tags
= prune
=
88 keep
= depth
= unshallow
= update_shallow
= refmap
=
89 curr_branch
=$
(git symbolic-ref
-q HEAD
)
90 curr_branch_short
="${curr_branch#refs/heads/}"
91 rebase
=$
(bool_or_string_config branch.
$curr_branch_short.rebase
)
94 rebase
=$
(bool_or_string_config pull.rebase
)
97 # Setup default fast-forward options via `pull.ff`
98 pull_ff
=$
(bool_or_string_config pull.ff
)
117 verbosity
="$verbosity -q" ;;
119 verbosity
="$verbosity -v" ;;
121 progress
=--progress ;;
123 progress
=--no-progress ;;
124 -n|
--no-stat|
--no-summary)
125 diffstat
=--no-stat ;;
128 --log|
--log=*|
--no-log)
131 no_commit
=--no-commit ;;
133 no_commit
=--commit ;;
141 squash
=--no-squash ;;
149 strategy_args
="$strategy_args $1"
151 -X*|
--strategy-option=*)
152 merge_args
="$merge_args $(git rev-parse --sq-quote "$1")"
163 --recurse-submodules)
164 recurse_submodules
=--recurse-submodules
166 --recurse-submodules=*)
167 recurse_submodules
="$1"
169 --no-recurse-submodules)
170 recurse_submodules
=--no-recurse-submodules
173 verify_signatures
=--verify-signatures
175 --no-verify-signatures)
176 verify_signatures
=--no-verify-signatures
182 gpg_sign_args
=$
(git rev-parse
--sq-quote "-S${1#--gpg-sign=}")
185 gpg_sign_args
=$
(git rev-parse
--sq-quote "$1")
192 -a|
--append|
--no-append)
194 --upload-pack=*|
--no-upload-pack)
196 -f|
--force|
--no-force)
200 -p|
--prune|
--no-prune)
204 --depth=*|
--no-depth)
206 --unshallow|
--no-unshallow)
208 --update-shallow|
--no-update-shallow)
210 --refmap=*|
--no-refmap)
229 rebase_args
=--preserve-merges
234 echo "Invalid value for --rebase, should be true, false, or preserve"
240 error_on_no_merge_candidates
() {
243 if test true
= "$rebase"
252 upstream
=$
(git config
"branch.$curr_branch_short.merge")
253 remote
=$
(git config
"branch.$curr_branch_short.remote")
255 if [ $# -gt 1 ]; then
256 if [ "$rebase" = true
]; then
257 printf "There is no candidate for rebasing against "
259 printf "There are no candidates for merging "
261 echo "among the refs that you just fetched."
262 echo "Generally this means that you provided a wildcard refspec which had no"
263 echo "matches on the remote end."
264 elif [ $# -gt 0 ] && [ "$1" != "$remote" ]; then
265 echo "You asked to pull from the remote '$1', but did not specify"
266 echo "a branch. Because this is not the default configured remote"
267 echo "for your current branch, you must specify a branch on the command line."
268 elif [ -z "$curr_branch" -o -z "$upstream" ]; then
270 error_on_missing_default_upstream
"pull" $op_type $op_prep \
271 "git pull <remote> <branch>"
273 echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
274 echo "from the remote, but no such ref was fetched."
279 test true
= "$rebase" && {
280 if ! git rev-parse
-q --verify HEAD
>/dev
/null
282 # On an unborn branch
283 if test -f "$(git rev-parse --git-path index)"
285 die
"$(gettext "updating an unborn branch with changes added to the index
")"
288 require_clean_work_tree
"pull with rebase" "Please commit or stash them."
291 test -n "$curr_branch" &&
292 . git-parse-remote
&&
293 remoteref
="$(get_remote_merge_branch "$@
" 2>/dev/null)" &&
294 oldremoteref
=$
(git merge-base
--fork-point "$remoteref" $curr_branch 2>/dev
/null
)
296 orig_head
=$
(git rev-parse
-q --verify HEAD
)
297 git fetch
$verbosity $progress $dry_run $recurse_submodules $all $append \
298 ${upload_pack:+"$upload_pack"} $force $tags $prune $keep $depth $unshallow $update_shallow \
299 $refmap --update-head-ok "$@" ||
exit 1
300 test -z "$dry_run" ||
exit 0
302 curr_head
=$
(git rev-parse
-q --verify HEAD
)
303 if test -n "$orig_head" && test "$curr_head" != "$orig_head"
305 # The fetch involved updating the current branch.
307 # The working tree and the index file is still based on the
308 # $orig_head commit, but we are merging into $curr_head.
309 # First update the working tree to match $curr_head.
311 eval_gettextln
"Warning: fetch updated the current branch head.
312 Warning: fast-forwarding your working tree from
313 Warning: commit \$orig_head." >&2
314 git update-index
-q --refresh
315 git read-tree
-u -m "$orig_head" "$curr_head" ||
316 die
"$(eval_gettext "Cannot fast-forward your working tree.
317 After making sure that you saved anything precious from
318 $ git
diff \
$orig_head
325 merge_head
=$
(sed -e '/ not-for-merge /d' \
326 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
329 case "$merge_head" in
331 error_on_no_merge_candidates
"$@"
334 if test -z "$orig_head"
336 die
"$(gettext "Cannot merge multiple branches into empty
head")"
338 if test true
= "$rebase"
340 die
"$(gettext "Cannot rebase onto multiple branches
")"
345 # Pulling into unborn branch: a shorthand for branching off
346 # FETCH_HEAD, for lazy typers.
347 if test -z "$orig_head"
349 # Two-way merge: we claim the index is based on an empty tree,
350 # and try to fast-forward to HEAD. This ensures we will not
351 # lose index/worktree changes that the user already made on
353 empty_tree
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
354 git read-tree
-m -u $empty_tree $merge_head &&
355 git update-ref
-m "initial pull" HEAD
$merge_head "$curr_head"
359 if test true
= "$rebase"
361 o
=$
(git show-branch
--merge-base $curr_branch $merge_head $oldremoteref)
362 if test "$oldremoteref" = "$o"
370 eval="git-rebase $diffstat $strategy_args $merge_args $rebase_args $verbosity"
371 eval="$eval $gpg_sign_args"
372 eval="$eval --onto $merge_head ${oldremoteref:-$merge_head}"
375 eval="git-merge $diffstat $no_commit $verify_signatures $edit $squash $no_ff $ff_only"
376 eval="$eval $log_arg $strategy_args $merge_args $verbosity $progress"
377 eval="$eval $gpg_sign_args"
378 eval="$eval FETCH_HEAD"