@@ -117,58 +117,7 @@ as well as various other special refspec forms:
117
117
linkgit:git-config[1]) suggest what refs/ namespace you may have
118
118
wanted to push to.
119
119
120
- The object referenced by <src > is used to update the <dst > reference
121
- on the remote side. Whether this is allowed depends on where in
122
- `refs/*` the <dst > reference lives as described in detail below, in
123
- those sections "update" means any modifications except deletes, which
124
- as noted after the next few sections are treated differently.
125
- +
126
- The `refs/heads/*` namespace will only accept commit objects, and
127
- updates only if they can be fast-forwarded.
128
- +
129
- The `refs/tags/*` namespace will accept any kind of object (as
130
- commits, trees and blobs can be tagged), and any updates to them will
131
- be rejected.
132
- +
133
- It's possible to push any type of object to any namespace outside of
134
- `refs/{tags,heads}/*` . In the case of tags and commits, these will be
135
- treated as if they were the commits inside `refs/heads/*` for the
136
- purposes of whether the update is allowed.
137
- +
138
- I.e. a fast-forward of commits and tags outside `refs/{tags,heads}/*`
139
- is allowed, even in cases where what's being fast-forwarded is not a
140
- commit, but a tag object which happens to point to a new commit which
141
- is a fast-forward of the commit the last tag (or commit) it's
142
- replacing. Replacing a tag with an entirely different tag is also
143
- allowed, if it points to the same commit, as well as pushing a peeled
144
- tag, i.e. pushing the commit that existing tag object points to, or a
145
- new tag object which an existing commit points to.
146
- +
147
- Tree and blob objects outside of `refs/{tags,heads}/*` will be treated
148
- the same way as if they were inside `refs/tags/*` , any update of them
149
- will be rejected.
150
- +
151
- All of the rules described above about what's not allowed as an update
152
- can be overridden by adding an the optional leading `+` to a refspec
153
- (or using `--force` command line option). The only exception to this
154
- is that no amount of forcing will make the `refs/heads/*` namespace
155
- accept a non-commit object. Hooks and configuration can also override
156
- or amend these rules, see e.g. `receive.denyNonFastForwards` in
157
- linkgit:git-config[1] and `pre-receive` and `update` in
158
- linkgit:githooks[5].
159
- +
160
- Pushing an empty <src > allows you to delete the <dst > ref from the
161
- remote repository. Deletions are always accepted without a leading `+`
162
- in the refspec (or `--force` ), except when forbidden by configuration
163
- or hooks. See `receive.denyDeletes` in linkgit:git-config[1] and
164
- `pre-receive` and `update` in linkgit:githooks[5].
165
- +
166
- The special refspec `:` (or `+:` to allow non-fast-forward updates)
167
- directs Git to push "matching" branches: for every branch that exists on
168
- the local side, the remote side is updated if a branch of the same name
169
- already exists on the remote side.
170
- +
171
- `tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>` .
120
+ Not all updates are allowed: see PUSH RULES below for the details.
172
121
173
122
-- all::
174
123
-- branches::
@@ -356,14 +305,10 @@ allowing a forced update.
356
305
357
306
-f::
358
307
-- force::
359
- Usually, the command refuses to update a remote ref that is
360
- not an ancestor of the local ref used to overwrite it.
361
- Also, when `--force-with-lease` option is used, the command refuses
362
- to update a remote ref whose current value does not match
363
- what is expected.
308
+ The `git push` command has safety checks (listed in PUSH RULES below).
364
309
+
365
- This flag disables these checks, and can cause the remote repository
366
- to lose commits; use it with care.
310
+ This flag disables these checks as well as the checks in -- force-with-lease,
311
+ and can cause the remote repository to lose commits; use it with care.
367
312
+
368
313
Note that `--force` applies to all the refs that are pushed, hence
369
314
using it with `push.default` set to `matching` or with multiple push
@@ -532,6 +477,44 @@ reason::
532
477
refs, no explanation is needed. For a failed ref, the reason for
533
478
failure is described.
534
479
480
+ PUSH RULES
481
+ ----------
482
+
483
+ As a safety feature, the `git push` command only allows certain kinds of
484
+ updates to prevent you from accidentally losing data on the remote.
485
+
486
+ Because branches and tags are intended to be used differently, the
487
+ safety rules for pushing to a branch are different from the rules
488
+ for pushing to a tag. In the following rules "update" means any
489
+ modifications except deletes. Deletions are always allowed, except when
490
+ forbidden by configuration or hooks.
491
+
492
+ 1. If the push destination is a **branch** (`refs/heads/*` ): only
493
+ fast-forward updates are allowed. The source must be a commit.
494
+ 2. If the push destination is a **tag** (`refs/tags/*` ): all updates will
495
+ be rejected. The source can be any object
496
+ (since commits, trees and blobs can be tagged).
497
+ 3. If the push destination is not a branch or tag:
498
+ * If the source is a tree or blob object, any updates will be rejected
499
+ * If the source is a tag or commit object, any fast-forward update
500
+ is allowed, even in cases where what's being fast-forwarded is not a
501
+ commit, but a tag object which happens to point to a new commit which
502
+ is a fast-forward of the commit the last tag (or commit) it's
503
+ replacing. Replacing a tag with an entirely different tag is also
504
+ allowed, if it points to the same commit, as well as pushing a peeled
505
+ tag, i.e. pushing the commit that existing tag object points to, or a
506
+ new tag object which an existing commit points to.
507
+
508
+ You can override these rules by passing `--force` or by adding the
509
+ optional leading `+` to a refspec. The only exception to this
510
+ is that no amount of forcing will make the `refs/heads/*` namespace
511
+ accept a non-commit object.
512
+
513
+ Hooks and configuration can also override or amend these rules,
514
+ see e.g. `receive.denyNonFastForwards` and `receive.denyDeletes`
515
+ in linkgit:git-config[1] and `pre-receive` and `update` in
516
+ linkgit:githooks[5].
517
+
535
518
NOTE ABOUT FAST-FORWARDS
536
519
------------------------
537
520
0 commit comments