···55555656<refspec>...::
5757 Specify what destination ref to update with what source object.
5858- The format of a <refspec> parameter is an optional plus
5959- `+`, followed by the source object <src>, followed
6060- by a colon `:`, followed by the destination ref <dst>.
6158+
6262-The <src> is often the name of the branch you would want to push, but
6363-it can be any arbitrary "SHA-1 expression", such as `master~4` or
6464-`HEAD` (see linkgit:gitrevisions[7]).
5959+The format for a refspec is [+]<src>[:<dst>], for example `main`,
6060+`main:other`, or `HEAD^:refs/heads/main`.
6561+
6666-The <dst> tells which ref on the remote side is updated with this
6767-push. Arbitrary expressions cannot be used here, an actual ref must
6868-be named.
6969-If `git push [<repository>]` without any `<refspec>` argument is set to
7070-update some ref at the destination with `<src>` with
7171-`remote.<repository>.push` configuration variable, `:<dst>` part can
7272-be omitted--such a push will update a ref that `<src>` normally updates
7373-without any `<refspec>` on the command line. Otherwise, missing
7474-`:<dst>` means to update the same ref as the `<src>`.
6262+The `<src>` is often the name of the local branch to push, but it can be
6363+any arbitrary "SHA-1 expression" (see linkgit:gitrevisions[7]).
7564+
7676-If <dst> doesn't start with `refs/` (e.g. `refs/heads/master`) we will
7777-try to infer where in `refs/*` on the destination <repository> it
7878-belongs based on the type of <src> being pushed and whether <dst>
7979-is ambiguous.
6565+The `<dst>` determines what ref to update on the remote side. It must be the
6666+name of a branch, tag, or other ref, not an arbitrary expression.
8067+
8181---
8282-* If <dst> unambiguously refers to a ref on the <repository> remote,
8383- then push to that ref.
8484-8585-* If <src> resolves to a ref starting with refs/heads/ or refs/tags/,
8686- then prepend that to <dst>.
8787-8888-* Other ambiguity resolutions might be added in the future, but for
8989- now any other cases will error out with an error indicating what we
9090- tried, and depending on the `advice.pushUnqualifiedRefname`
9191- configuration (see linkgit:git-config[1]) suggest what refs/
9292- namespace you may have wanted to push to.
9393-9494---
6868+The `+` is optional and does the same thing as `--force`.
9569+
9696-The object referenced by <src> is used to update the <dst> reference
9797-on the remote side. Whether this is allowed depends on where in
9898-`refs/*` the <dst> reference lives as described in detail below, in
9999-those sections "update" means any modifications except deletes, which
100100-as noted after the next few sections are treated differently.
7070+You can write a refspec using the fully expanded form (for
7171+example `refs/heads/main:refs/heads/main`) which specifies the exact source
7272+and destination, or with a shorter form (for example `main` or
7373+`main:other`). Here are the rules for how refspecs are expanded,
7474+as well as various other special refspec forms:
10175+
102102-The `refs/heads/*` namespace will only accept commit objects, and
103103-updates only if they can be fast-forwarded.
104104-+
105105-The `refs/tags/*` namespace will accept any kind of object (as
106106-commits, trees and blobs can be tagged), and any updates to them will
107107-be rejected.
108108-+
109109-It's possible to push any type of object to any namespace outside of
110110-`refs/{tags,heads}/*`. In the case of tags and commits, these will be
111111-treated as if they were the commits inside `refs/heads/*` for the
112112-purposes of whether the update is allowed.
113113-+
114114-I.e. a fast-forward of commits and tags outside `refs/{tags,heads}/*`
115115-is allowed, even in cases where what's being fast-forwarded is not a
116116-commit, but a tag object which happens to point to a new commit which
117117-is a fast-forward of the commit the last tag (or commit) it's
118118-replacing. Replacing a tag with an entirely different tag is also
119119-allowed, if it points to the same commit, as well as pushing a peeled
120120-tag, i.e. pushing the commit that existing tag object points to, or a
121121-new tag object which an existing commit points to.
122122-+
123123-Tree and blob objects outside of `refs/{tags,heads}/*` will be treated
124124-the same way as if they were inside `refs/tags/*`, any update of them
125125-will be rejected.
126126-+
127127-All of the rules described above about what's not allowed as an update
128128-can be overridden by adding an the optional leading `+` to a refspec
129129-(or using `--force` command line option). The only exception to this
130130-is that no amount of forcing will make the `refs/heads/*` namespace
131131-accept a non-commit object. Hooks and configuration can also override
132132-or amend these rules, see e.g. `receive.denyNonFastForwards` in
133133-linkgit:git-config[1] and `pre-receive` and `update` in
134134-linkgit:githooks[5].
135135-+
136136-Pushing an empty <src> allows you to delete the <dst> ref from the
137137-remote repository. Deletions are always accepted without a leading `+`
138138-in the refspec (or `--force`), except when forbidden by configuration
139139-or hooks. See `receive.denyDeletes` in linkgit:git-config[1] and
140140-`pre-receive` and `update` in linkgit:githooks[5].
141141-+
142142-The special refspec `:` (or `+:` to allow non-fast-forward updates)
143143-directs Git to push "matching" branches: for every branch that exists on
144144-the local side, the remote side is updated if a branch of the same name
145145-already exists on the remote side.
146146-+
147147-`tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`.
7676+ * `<src>` without a `:<dst>` means to update the same ref as the
7777+ `<src>`, unless the `remote.<repository>.push` configuration specifies a
7878+ different <dst>. For example, if `main` is a branch, then the refspec
7979+ `main` expands to `main:refs/heads/main`.
8080+ * If `<dst>` unambiguously refers to a ref on the <repository> remote,
8181+ then expand it to that ref. For example, if `v1.0` is a tag on the
8282+ remote, then `HEAD:v1.0` expands to `HEAD:refs/tags/v1.0`.
8383+ * If `<src>` resolves to a ref starting with `refs/heads/` or `refs/tags/`,
8484+ then prepend that to <dst>. For example, if `main` is a branch, then
8585+ `main:other` expands to `main:refs/heads/other`
8686+ * The special refspec `:` (or `+:` to allow non-fast-forward updates)
8787+ directs Git to push "matching" branches: for every branch that exists on
8888+ the local side, the remote side is updated if a branch of the same name
8989+ already exists on the remote side.
9090+ * <src> may contain a * to indicate a simple pattern match.
9191+ This works like a glob that matches any ref matching the pattern.
9292+ There must be only one * in both the `<src>` and `<dst>`.
9393+ It will map refs to the destination by replacing the * with the
9494+ contents matched from the source. For example, `refs/heads/*:refs/heads/*`
9595+ will push all branches.
9696+ * A refspec starting with `^` is a negative refspec.
9797+ This specifies refs to exclude. A ref will be considered to
9898+ match if it matches at least one positive refspec, and does not
9999+ match any negative refspec. Negative refspecs can be pattern refspecs.
100100+ They must only contain a `<src>`.
101101+ Fully spelled out hex object names are also not supported.
102102+ For example, `git push origin 'refs/heads/*' '^refs/heads/dev-*'`
103103+ will push all branches except for those starting with `dev-`
104104+ * If `<src>` is empty, it deletes the `<dst>` ref from the remote
105105+ repository. For example, `git push origin :dev` will
106106+ delete the `dev` branch.
107107+ * `tag <tag>` expands to `refs/tags/<tag>:refs/tags/<tag>`.
108108+ This is technically a special syntax for `git push` and not a refspec,
109109+ since in `git push origin tag v1.0` the arguments `tag` and `v1.0`
110110+ are separate.
111111+ * If the refspec can't be expanded unambiguously, error out
112112+ with an error indicating what was tried, and depending
113113+ on the `advice.pushUnqualifiedRefname` configuration (see
114114+ linkgit:git-config[1]) suggest what refs/ namespace you may have
115115+ wanted to push to.
116116+117117+Not all updates are allowed: see PUSH RULES below for the details.
148118149119--all::
150120--branches::
···335305336306-f::
337307--force::
338338- Usually, the command refuses to update a remote ref that is
339339- not an ancestor of the local ref used to overwrite it.
340340- Also, when `--force-with-lease` option is used, the command refuses
341341- to update a remote ref whose current value does not match
342342- what is expected.
308308+ Usually, `git push` will refuse to update a branch that is not an
309309+ ancestor of the commit being pushed.
343310+
344344-This flag disables these checks, and can cause the remote repository
345345-to lose commits; use it with care.
311311+This flag disables that check, the other safety checks in PUSH RULES
312312+below, and the checks in --force-with-lease. It can cause the remote
313313+repository to lose commits; use it with care.
346314+
347315Note that `--force` applies to all the refs that are pushed, hence
348316using it with `push.default` set to `matching` or with multiple push
···513481 A human-readable explanation. In the case of successfully pushed
514482 refs, no explanation is needed. For a failed ref, the reason for
515483 failure is described.
484484+485485+PUSH RULES
486486+----------
487487+488488+As a safety feature, the `git push` command only allows certain kinds of
489489+updates to prevent you from accidentally losing data on the remote.
490490+491491+Because branches and tags are intended to be used differently, the
492492+safety rules for pushing to a branch are different from the rules
493493+for pushing to a tag. In the following rules "update" means any
494494+modifications except deletions and creations. Deletions and creations
495495+are always allowed, except when forbidden by configuration or hooks.
496496+497497+1. If the push destination is a **branch** (`refs/heads/*`): only
498498+ fast-forward updates are allowed, which means the destination must be
499499+ an ancestor of the source commit. The source must be a commit.
500500+2. If the push destination is a **tag** (`refs/tags/*`): all updates will
501501+ be rejected. The source can be any object.
502502+3. If the push destination is not a branch or tag:
503503+ * If the source is a tree or blob object, any updates will be rejected
504504+ * If the source is a tag or commit object, any fast-forward update
505505+ is allowed, even in cases where what's being fast-forwarded is not a
506506+ commit, but a tag object which happens to point to a new commit which
507507+ is a fast-forward of the commit the last tag (or commit) it's
508508+ replacing. Replacing a tag with an entirely different tag is also
509509+ allowed, if it points to the same commit, as well as pushing a peeled
510510+ tag, i.e. pushing the commit that existing tag object points to, or a
511511+ new tag object which an existing commit points to.
512512+513513+You can override these rules by passing `--force` or by adding the
514514+optional leading `+` to a refspec. The only exceptions are that no
515515+amount of forcing will make a branch accept a non-commit object,
516516+and forcing won't make the remote repository accept a push that it's
517517+configured to deny.
518518+519519+Hooks and configuration can also override or amend these rules,
520520+see e.g. `receive.denyNonFastForwards` and `receive.denyDeletes`
521521+in linkgit:git-config[1] and `pre-receive` and `update` in
522522+linkgit:githooks[5].
516523517524NOTE ABOUT FAST-FORWARDS
518525------------------------