@@ -56,7 +56,7 @@ OPTIONS[[OPTIONS]]
56
56
of a remote (see the section <<REMOTES,REMOTES>> below).
57
57
58
58
<refspec >... ::
59
- Specify what destination branch or tag (or other reference) to update
59
+ Specify what destination branch or tag (or other reference) to update ▐
60
60
with what source commit (or other object).
61
61
+
62
62
The format for a refspec is [+]<src >[:<dst >], for example `main` ,
@@ -70,33 +70,53 @@ name of a branch, tag, or other ref, not an arbitrary expression.
70
70
+
71
71
The `+` is optional and does the same thing as `--force` .
72
72
+
73
- If `git push [<repository>]` without any `<refspec>` argument is set to
74
- update some ref at the destination with `<src>` with
75
- `remote.<repository>.push` configuration variable, `:<dst>` part can
76
- be omitted-- such a push will update a ref that `<src>` normally updates
77
- without any `<refspec>` on the command line. Otherwise, missing
78
- `:<dst>` means to update the same ref as the `<src>` .
79
- +
80
- If <dst > doesn't start with `refs/` (e.g. `refs/heads/master` ) we will
81
- try to infer where in `refs/*` on the destination <repository > it
82
- belongs based on the type of <src > being pushed and whether <dst >
83
- is ambiguous.
84
- +
85
- --
86
- * If <dst > unambiguously refers to a ref on the <repository > remote,
87
- then push to that ref.
88
-
89
- * If <src> resolves to a ref starting with refs/heads/ or refs/tags/,
90
- then prepend that to <dst>.
73
+ You can write a refspec using the fully expanded form (for
74
+ example `refs/heads/main:refs/heads/main` ) which specifies the exact source
75
+ and destination, or with a shorter form (for example `main` or
76
+ `main:other` ). Here are the rules for how refspecs are expanded,
77
+ as well as various other special refspec forms:
78
+ +
79
+ * `<src>` without a `:<dst>` means to update the same ref as the
80
+ `<src>` , unless the `remote.<repository>.push` configuration specifies a
81
+ different <dst >. For example, if `main` is a branch, then the refspec
82
+ `main` expands to `main:refs/heads/main` .
83
+ * If `<dst>` unambiguously refers to a ref on the <repository > remote,
84
+ then expand it to that ref. For example, if `v1.0` is a tag on the
85
+ remote, then `HEAD:v1.0` expands to `HEAD:refs/tags/v1.0` .
86
+ * If `<src>` resolves to a ref starting with `refs/heads/` or `refs/tags/` ,
87
+ then prepend that to <dst >. For example, if `main` is a branch, then
88
+ `main:other` expands to `main:refs/heads/other`
89
+ * The special refspec `:` (or `+:` to allow non-fast-forward updates)
90
+ directs Git to push "matching" branches: for every branch that exists on
91
+ the local side, the remote side is updated if a branch of the same name
92
+ already exists on the remote side.
93
+ * <src > may contain a * to indicate a simple pattern match.
94
+ This works like a glob that matches any ref matching the pattern.
95
+ There must be only one * in both the `<src>` and `<dst>` .
96
+ It will map refs to the destination by replacing the * with the
97
+ contents matched from the source. For example, `refs/heads/*:refs/heads/*`
98
+ will push all branches.
99
+ * A refspec starting with `^` is a negative refspec.
100
+ This specifies refs to exclude. A ref will be considered to
101
+ match if it matches at least one positive refspec, and does not
102
+ match any negative refspec. Negative refspecs can be pattern refspecs.
103
+ They must only contain a `<src>` .
104
+ Fully spelled out hex object names are also not supported.
105
+ For example, `git push origin 'refs/heads/*' '^refs/heads/dev-*'`
106
+ will push all branches except for those starting with `dev-`
107
+ * If `<src>` is empty, it deletes the `<dst>` ref from the remote
108
+ repository. For example, `git push origin :dev` will
109
+ delete the `dev` branch.
110
+ * `tag <tag>` expands to `refs/tags/<tag>:refs/tags/<tag>` .
111
+ This is technically a special syntax for `git push` and not a refspec,
112
+ since in `git push origin tag v1.0` `tag` and `v1.0` are separate
113
+ arguments.
114
+ * If the refspec can't be expanded unambiguously, error out
115
+ with an error indicating what was tried, and depending
116
+ on the `advice.pushUnqualifiedRefname` configuration (see
117
+ linkgit:git-config[1]) suggest what refs/ namespace you may have
118
+ wanted to push to.
91
119
92
- * Other ambiguity resolutions might be added in the future, but for
93
- now any other cases will error out with an error indicating what we
94
- tried, and depending on the `advice.pushUnqualifiedRefname`
95
- configuration (see linkgit:git-config[1]) suggest what refs/
96
- namespace you may have wanted to push to.
97
-
98
- --
99
- +
100
120
The object referenced by <src > is used to update the <dst > reference
101
121
on the remote side. Whether this is allowed depends on where in
102
122
`refs/*` the <dst > reference lives as described in detail below, in
0 commit comments