fetch: document local ref updates with/without --force
[git] / Documentation / pull-fetch-param.txt
1 <repository>::
2         The "remote" repository that is the source of a fetch
3         or pull operation.  This parameter can be either a URL
4         (see the section <<URLS,GIT URLS>> below) or the name
5         of a remote (see the section <<REMOTES,REMOTES>> below).
6
7 ifndef::git-pull[]
8 <group>::
9         A name referring to a list of repositories as the value
10         of remotes.<group> in the configuration file.
11         (See linkgit:git-config[1]).
12 endif::git-pull[]
13
14 <refspec>::
15         Specifies which refs to fetch and which local refs to update.
16         When no <refspec>s appear on the command line, the refs to fetch
17         are read from `remote.<repository>.fetch` variables instead
18 ifndef::git-pull[]
19         (see <<CRTB,CONFIGURED REMOTE-TRACKING BRANCHES>> below).
20 endif::git-pull[]
21 ifdef::git-pull[]
22         (see linkgit:git-fetch[1]).
23 endif::git-pull[]
24 +
25 The format of a <refspec> parameter is an optional plus
26 `+`, followed by the source <src>, followed
27 by a colon `:`, followed by the destination ref <dst>.
28 The colon can be omitted when <dst> is empty.  <src> is
29 typically a ref, but it can also be a fully spelled hex object
30 name.
31 +
32 `tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`;
33 it requests fetching everything up to the given tag.
34 +
35 The remote ref that matches <src>
36 is fetched, and if <dst> is not an empty string, an attempt
37 is made to update the local ref that matches it.
38 +
39 Whether that update is allowed without `--force` depends on the ref
40 namespace it's being fetched to, the type of object being fetched, and
41 whether the update is considered to be a fast-forward. Generally, the
42 same rules apply for fetching as when pushing, see the `<refspec>...`
43 section of linkgit:git-push[1] for what those are. Exceptions to those
44 rules particular to 'git fetch' are noted below.
45 +
46 Unlike when pushing with linkgit:git-push[1], any updates to
47 `refs/tags/*` will be accepted without `+` in the refspec (or
48 `--force`). The receiving promiscuously considers all tag updates from
49 a remote to be forced fetches.
50 +
51 Unlike when pushing with linkgit:git-push[1], any updates outside of
52 `refs/{tags,heads}/*` will be accepted without `+` in the refspec (or
53 `--force`), whether that's swapping e.g. a tree object for a blob, or
54 a commit for another commit that's doesn't have the previous commit as
55 an ancestor etc.
56 +
57 As with pushing with linkgit:git-push[1], all of the rules described
58 above about what's not allowed as an update can be overridden by
59 adding an the optional leading `+` to a refspec (or using `--force`
60 command line option). The only exception to this is that no amount of
61 forcing will make the `refs/heads/*` namespace accept a non-commit
62 object.
63 +
64 [NOTE]
65 When the remote branch you want to fetch is known to
66 be rewound and rebased regularly, it is expected that
67 its new tip will not be descendant of its previous tip
68 (as stored in your remote-tracking branch the last time
69 you fetched).  You would want
70 to use the `+` sign to indicate non-fast-forward updates
71 will be needed for such branches.  There is no way to
72 determine or declare that a branch will be made available
73 in a repository with this behavior; the pulling user simply
74 must know this is the expected usage pattern for a branch.
75 ifdef::git-pull[]
76 +
77 [NOTE]
78 There is a difference between listing multiple <refspec>
79 directly on 'git pull' command line and having multiple
80 `remote.<repository>.fetch` entries in your configuration
81 for a <repository> and running a
82 'git pull' command without any explicit <refspec> parameters.
83 <refspec>s listed explicitly on the command line are always
84 merged into the current branch after fetching.  In other words,
85 if you list more than one remote ref, 'git pull' will create
86 an Octopus merge.  On the other hand, if you do not list any
87 explicit <refspec> parameter on the command line, 'git pull'
88 will fetch all the <refspec>s it finds in the
89 `remote.<repository>.fetch` configuration and merge
90 only the first <refspec> found into the current branch.
91 This is because making an
92 Octopus from remote refs is rarely done, while keeping track
93 of multiple remote heads in one-go by fetching more than one
94 is often useful.
95 endif::git-pull[]