Skip to content

Commit dc29bc8

Browse files
committed
tutorial: clarify "pull" is "fetch + merge"
The document says that a fetch with a configured remote stores what are fetched in the remote tracking branches "Unlike the longhand form", but there is no longhand form "fetch" demonstrated earlier. This adds a missing demonstration of the longhand form, and a new paragraph to explain why some people might want to fetch before pull. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5d5e88a commit dc29bc8

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

Documentation/gittutorial.txt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,32 @@ is the default.)
306306
The "pull" command thus performs two operations: it fetches changes
307307
from a remote branch, then merges them into the current branch.
308308

309+
Note that in general, Alice would want her local changes committed before
310+
initiating this "pull". If Bob's work conflicts with what Alice did since
311+
their histories forked, Alice will use her working tree and the index to
312+
resolve conflicts, and existing local changes will interfere with the
313+
conflict resolution process (git will still perform the fetch but will
314+
refuse to merge --- Alice will have to get rid of her local changes in
315+
some way and pull again when this happens).
316+
317+
Alice can peek at what Bob did without merging first, using the "fetch"
318+
command; this allows Alice to inspect what Bob did, using a special
319+
symbol "FETCH_HEAD", in order to determine if he has anything worth
320+
pulling, like this:
321+
322+
------------------------------------------------
323+
alice$ git fetch /home/bob/myrepo master
324+
alice$ git log -p ..FETCH_HEAD
325+
------------------------------------------------
326+
327+
This operation is safe even if Alice has uncommitted local changes.
328+
329+
After inspecting what Bob did, if there is nothing urgent, Alice may
330+
decide to continue working without pulling from Bob. If Bob's history
331+
does have something Alice would immediately need, Alice may choose to
332+
stash her work-in-progress first, do a "pull", and then finally unstash
333+
her work-in-progress on top of the resulting history.
334+
309335
When you are working in a small closely knit group, it is not
310336
unusual to interact with the same repository over and over
311337
again. By defining 'remote' repository shorthand, you can make
@@ -315,7 +341,7 @@ it easier:
315341
alice$ git remote add bob /home/bob/myrepo
316342
------------------------------------------------
317343

318-
With this, Alice can perform the first operation alone using the
344+
With this, Alice can perform the first part of the "pull" operation alone using the
319345
'git-fetch' command without merging them with her own branch,
320346
using:
321347

0 commit comments

Comments
 (0)