1GIT-PUSH(1) Git Manual GIT-PUSH(1)
2
3
4
6 git-push - Update remote refs along with associated objects
7
9 git push [--all | --branches | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
10 [--repo=<repository>] [-f | --force] [-d | --delete] [--prune] [-q | --quiet] [-v | --verbose]
11 [-u | --set-upstream] [-o <string> | --push-option=<string>]
12 [--[no-]signed|--signed=(true|false|if-asked)]
13 [--force-with-lease[=<refname>[:<expect>]] [--force-if-includes]]
14 [--no-verify] [<repository> [<refspec>...]]
15
17 Updates remote refs using local refs, while sending objects necessary
18 to complete the given refs.
19
20 You can make interesting things happen to a repository every time you
21 push into it, by setting up hooks there. See documentation for git-
22 receive-pack(1).
23
24 When the command line does not specify where to push with the
25 <repository> argument, branch.*.remote configuration for the current
26 branch is consulted to determine where to push. If the configuration is
27 missing, it defaults to origin.
28
29 When the command line does not specify what to push with <refspec>...
30 arguments or --all, --mirror, --tags options, the command finds the
31 default <refspec> by consulting remote.*.push configuration, and if it
32 is not found, honors push.default configuration to decide what to push
33 (See git-config(1) for the meaning of push.default).
34
35 When neither the command-line nor the configuration specifies what to
36 push, the default behavior is used, which corresponds to the simple
37 value for push.default: the current branch is pushed to the
38 corresponding upstream branch, but as a safety measure, the push is
39 aborted if the upstream branch does not have the same name as the local
40 one.
41
43 <repository>
44 The "remote" repository that is the destination of a push
45 operation. This parameter can be either a URL (see the section GIT
46 URLS below) or the name of a remote (see the section REMOTES
47 below).
48
49 <refspec>...
50 Specify what destination ref to update with what source object. The
51 format of a <refspec> parameter is an optional plus +, followed by
52 the source object <src>, followed by a colon :, followed by the
53 destination ref <dst>.
54
55 The <src> is often the name of the branch you would want to push,
56 but it can be any arbitrary "SHA-1 expression", such as master~4 or
57 HEAD (see gitrevisions(7)).
58
59 The <dst> tells which ref on the remote side is updated with this
60 push. Arbitrary expressions cannot be used here, an actual ref must
61 be named. If git push [<repository>] without any <refspec> argument
62 is set to update some ref at the destination with <src> with
63 remote.<repository>.push configuration variable, :<dst> part can be
64 omitted—such a push will update a ref that <src> normally updates
65 without any <refspec> on the command line. Otherwise, missing
66 :<dst> means to update the same ref as the <src>.
67
68 If <dst> doesn’t start with refs/ (e.g. refs/heads/master) we will
69 try to infer where in refs/* on the destination <repository> it
70 belongs based on the type of <src> being pushed and whether <dst>
71 is ambiguous.
72
73 • If <dst> unambiguously refers to a ref on the <repository>
74 remote, then push to that ref.
75
76 • If <src> resolves to a ref starting with refs/heads/ or
77 refs/tags/, then prepend that to <dst>.
78
79 • Other ambiguity resolutions might be added in the future, but
80 for now any other cases will error out with an error indicating
81 what we tried, and depending on the
82 advice.pushUnqualifiedRefname configuration (see git-config(1))
83 suggest what refs/ namespace you may have wanted to push to.
84
85 The object referenced by <src> is used to update the <dst>
86 reference on the remote side. Whether this is allowed depends on
87 where in refs/* the <dst> reference lives as described in detail
88 below, in those sections "update" means any modifications except
89 deletes, which as noted after the next few sections are treated
90 differently.
91
92 The refs/heads/* namespace will only accept commit objects, and
93 updates only if they can be fast-forwarded.
94
95 The refs/tags/* namespace will accept any kind of object (as
96 commits, trees and blobs can be tagged), and any updates to them
97 will be rejected.
98
99 It’s possible to push any type of object to any namespace outside
100 of refs/{tags,heads}/*. In the case of tags and commits, these will
101 be treated as if they were the commits inside refs/heads/* for the
102 purposes of whether the update is allowed.
103
104 I.e. a fast-forward of commits and tags outside refs/{tags,heads}/*
105 is allowed, even in cases where what’s being fast-forwarded is not
106 a commit, but a tag object which happens to point to a new commit
107 which is a fast-forward of the commit the last tag (or commit) it’s
108 replacing. Replacing a tag with an entirely different tag is also
109 allowed, if it points to the same commit, as well as pushing a
110 peeled tag, i.e. pushing the commit that existing tag object points
111 to, or a new tag object which an existing commit points to.
112
113 Tree and blob objects outside of refs/{tags,heads}/* will be
114 treated the same way as if they were inside refs/tags/*, any update
115 of them will be rejected.
116
117 All of the rules described above about what’s not allowed as an
118 update can be overridden by adding an the optional leading + to a
119 refspec (or using --force command line option). The only exception
120 to this is that no amount of forcing will make the refs/heads/*
121 namespace accept a non-commit object. Hooks and configuration can
122 also override or amend these rules, see e.g.
123 receive.denyNonFastForwards in git-config(1) and pre-receive and
124 update in githooks(5).
125
126 Pushing an empty <src> allows you to delete the <dst> ref from the
127 remote repository. Deletions are always accepted without a leading
128 + in the refspec (or --force), except when forbidden by
129 configuration or hooks. See receive.denyDeletes in git-config(1)
130 and pre-receive and update in githooks(5).
131
132 The special refspec : (or +: to allow non-fast-forward updates)
133 directs Git to push "matching" branches: for every branch that
134 exists on the local side, the remote side is updated if a branch of
135 the same name already exists on the remote side.
136
137 tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>.
138
139 --all, --branches
140 Push all branches (i.e. refs under refs/heads/); cannot be used
141 with other <refspec>.
142
143 --prune
144 Remove remote branches that don’t have a local counterpart. For
145 example a remote branch tmp will be removed if a local branch with
146 the same name doesn’t exist any more. This also respects refspecs,
147 e.g. git push --prune remote refs/heads/*:refs/tmp/* would make
148 sure that remote refs/tmp/foo will be removed if refs/heads/foo
149 doesn’t exist.
150
151 --mirror
152 Instead of naming each ref to push, specifies that all refs under
153 refs/ (which includes but is not limited to refs/heads/,
154 refs/remotes/, and refs/tags/) be mirrored to the remote
155 repository. Newly created local refs will be pushed to the remote
156 end, locally updated refs will be force updated on the remote end,
157 and deleted refs will be removed from the remote end. This is the
158 default if the configuration option remote.<remote>.mirror is set.
159
160 -n, --dry-run
161 Do everything except actually send the updates.
162
163 --porcelain
164 Produce machine-readable output. The output status line for each
165 ref will be tab-separated and sent to stdout instead of stderr. The
166 full symbolic names of the refs will be given.
167
168 -d, --delete
169 All listed refs are deleted from the remote repository. This is the
170 same as prefixing all refs with a colon.
171
172 --tags
173 All refs under refs/tags are pushed, in addition to refspecs
174 explicitly listed on the command line.
175
176 --follow-tags
177 Push all the refs that would be pushed without this option, and
178 also push annotated tags in refs/tags that are missing from the
179 remote but are pointing at commit-ish that are reachable from the
180 refs being pushed. This can also be specified with configuration
181 variable push.followTags. For more information, see push.followTags
182 in git-config(1).
183
184 --[no-]signed, --signed=(true|false|if-asked)
185 GPG-sign the push request to update refs on the receiving side, to
186 allow it to be checked by the hooks and/or be logged. If false or
187 --no-signed, no signing will be attempted. If true or --signed, the
188 push will fail if the server does not support signed pushes. If set
189 to if-asked, sign if and only if the server supports signed pushes.
190 The push will also fail if the actual call to gpg --sign fails. See
191 git-receive-pack(1) for the details on the receiving end.
192
193 --[no-]atomic
194 Use an atomic transaction on the remote side if available. Either
195 all refs are updated, or on error, no refs are updated. If the
196 server does not support atomic pushes the push will fail.
197
198 -o <option>, --push-option=<option>
199 Transmit the given string to the server, which passes them to the
200 pre-receive as well as the post-receive hook. The given string must
201 not contain a NUL or LF character. When multiple
202 --push-option=<option> are given, they are all sent to the other
203 side in the order listed on the command line. When no
204 --push-option=<option> is given from the command line, the values
205 of configuration variable push.pushOption are used instead.
206
207 --receive-pack=<git-receive-pack>, --exec=<git-receive-pack>
208 Path to the git-receive-pack program on the remote end. Sometimes
209 useful when pushing to a remote repository over ssh, and you do not
210 have the program in a directory on the default $PATH.
211
212 --[no-]force-with-lease, --force-with-lease=<refname>,
213 --force-with-lease=<refname>:<expect>
214 Usually, "git push" refuses to update a remote ref that is not an
215 ancestor of the local ref used to overwrite it.
216
217 This option overrides this restriction if the current value of the
218 remote ref is the expected value. "git push" fails otherwise.
219
220 Imagine that you have to rebase what you have already published.
221 You will have to bypass the "must fast-forward" rule in order to
222 replace the history you originally published with the rebased
223 history. If somebody else built on top of your original history
224 while you are rebasing, the tip of the branch at the remote may
225 advance with their commit, and blindly pushing with --force will
226 lose their work.
227
228 This option allows you to say that you expect the history you are
229 updating is what you rebased and want to replace. If the remote ref
230 still points at the commit you specified, you can be sure that no
231 other people did anything to the ref. It is like taking a "lease"
232 on the ref without explicitly locking it, and the remote ref is
233 updated only if the "lease" is still valid.
234
235 --force-with-lease alone, without specifying the details, will
236 protect all remote refs that are going to be updated by requiring
237 their current value to be the same as the remote-tracking branch we
238 have for them.
239
240 --force-with-lease=<refname>, without specifying the expected
241 value, will protect the named ref (alone), if it is going to be
242 updated, by requiring its current value to be the same as the
243 remote-tracking branch we have for it.
244
245 --force-with-lease=<refname>:<expect> will protect the named ref
246 (alone), if it is going to be updated, by requiring its current
247 value to be the same as the specified value <expect> (which is
248 allowed to be different from the remote-tracking branch we have for
249 the refname, or we do not even have to have such a remote-tracking
250 branch when this form is used). If <expect> is the empty string,
251 then the named ref must not already exist.
252
253 Note that all forms other than
254 --force-with-lease=<refname>:<expect> that specifies the expected
255 current value of the ref explicitly are still experimental and
256 their semantics may change as we gain experience with this feature.
257
258 "--no-force-with-lease" will cancel all the previous
259 --force-with-lease on the command line.
260
261 A general note on safety: supplying this option without an expected
262 value, i.e. as --force-with-lease or --force-with-lease=<refname>
263 interacts very badly with anything that implicitly runs git fetch
264 on the remote to be pushed to in the background, e.g. git fetch
265 origin on your repository in a cronjob.
266
267 The protection it offers over --force is ensuring that subsequent
268 changes your work wasn’t based on aren’t clobbered, but this is
269 trivially defeated if some background process is updating refs in
270 the background. We don’t have anything except the remote tracking
271 info to go by as a heuristic for refs you’re expected to have seen
272 & are willing to clobber.
273
274 If your editor or some other system is running git fetch in the
275 background for you a way to mitigate this is to simply set up
276 another remote:
277
278 git remote add origin-push $(git config remote.origin.url)
279 git fetch origin-push
280
281 Now when the background process runs git fetch origin the
282 references on origin-push won’t be updated, and thus commands like:
283
284 git push --force-with-lease origin-push
285
286 Will fail unless you manually run git fetch origin-push. This
287 method is of course entirely defeated by something that runs git
288 fetch --all, in that case you’d need to either disable it or do
289 something more tedious like:
290
291 git fetch # update 'master' from remote
292 git tag base master # mark our base point
293 git rebase -i master # rewrite some commits
294 git push --force-with-lease=master:base master:master
295
296 I.e. create a base tag for versions of the upstream code that
297 you’ve seen and are willing to overwrite, then rewrite history, and
298 finally force push changes to master if the remote version is still
299 at base, regardless of what your local remotes/origin/master has
300 been updated to in the background.
301
302 Alternatively, specifying --force-if-includes as an ancillary
303 option along with --force-with-lease[=<refname>] (i.e., without
304 saying what exact commit the ref on the remote side must be
305 pointing at, or which refs on the remote side are being protected)
306 at the time of "push" will verify if updates from the
307 remote-tracking refs that may have been implicitly updated in the
308 background are integrated locally before allowing a forced update.
309
310 -f, --force
311 Usually, the command refuses to update a remote ref that is not an
312 ancestor of the local ref used to overwrite it. Also, when
313 --force-with-lease option is used, the command refuses to update a
314 remote ref whose current value does not match what is expected.
315
316 This flag disables these checks, and can cause the remote
317 repository to lose commits; use it with care.
318
319 Note that --force applies to all the refs that are pushed, hence
320 using it with push.default set to matching or with multiple push
321 destinations configured with remote.*.push may overwrite refs other
322 than the current branch (including local refs that are strictly
323 behind their remote counterpart). To force a push to only one
324 branch, use a + in front of the refspec to push (e.g git push
325 origin +master to force a push to the master branch). See the
326 <refspec>... section above for details.
327
328 --[no-]force-if-includes
329 Force an update only if the tip of the remote-tracking ref has been
330 integrated locally.
331
332 This option enables a check that verifies if the tip of the
333 remote-tracking ref is reachable from one of the "reflog" entries
334 of the local branch based in it for a rewrite. The check ensures
335 that any updates from the remote have been incorporated locally by
336 rejecting the forced update if that is not the case.
337
338 If the option is passed without specifying --force-with-lease, or
339 specified along with --force-with-lease=<refname>:<expect>, it is a
340 "no-op".
341
342 Specifying --no-force-if-includes disables this behavior.
343
344 --repo=<repository>
345 This option is equivalent to the <repository> argument. If both are
346 specified, the command-line argument takes precedence.
347
348 -u, --set-upstream
349 For every branch that is up to date or successfully pushed, add
350 upstream (tracking) reference, used by argument-less git-pull(1)
351 and other commands. For more information, see branch.<name>.merge
352 in git-config(1).
353
354 --[no-]thin
355 These options are passed to git-send-pack(1). A thin transfer
356 significantly reduces the amount of sent data when the sender and
357 receiver share many of the same objects in common. The default is
358 --thin.
359
360 -q, --quiet
361 Suppress all output, including the listing of updated refs, unless
362 an error occurs. Progress is not reported to the standard error
363 stream.
364
365 -v, --verbose
366 Run verbosely.
367
368 --progress
369 Progress status is reported on the standard error stream by default
370 when it is attached to a terminal, unless -q is specified. This
371 flag forces progress status even if the standard error stream is
372 not directed to a terminal.
373
374 --no-recurse-submodules, --recurse-submodules=check|on-demand|only|no
375 May be used to make sure all submodule commits used by the
376 revisions to be pushed are available on a remote-tracking branch.
377 If check is used Git will verify that all submodule commits that
378 changed in the revisions to be pushed are available on at least one
379 remote of the submodule. If any commits are missing the push will
380 be aborted and exit with non-zero status. If on-demand is used all
381 submodules that changed in the revisions to be pushed will be
382 pushed. If on-demand was not able to push all necessary revisions
383 it will also be aborted and exit with non-zero status. If only is
384 used all submodules will be pushed while the superproject is left
385 unpushed. A value of no or using --no-recurse-submodules can be
386 used to override the push.recurseSubmodules configuration variable
387 when no submodule recursion is required.
388
389 When using on-demand or only, if a submodule has a
390 "push.recurseSubmodules={on-demand,only}" or "submodule.recurse"
391 configuration, further recursion will occur. In this case, "only"
392 is treated as "on-demand".
393
394 --[no-]verify
395 Toggle the pre-push hook (see githooks(5)). The default is
396 --verify, giving the hook a chance to prevent the push. With
397 --no-verify, the hook is bypassed completely.
398
399 -4, --ipv4
400 Use IPv4 addresses only, ignoring IPv6 addresses.
401
402 -6, --ipv6
403 Use IPv6 addresses only, ignoring IPv4 addresses.
404
406 In general, URLs contain information about the transport protocol, the
407 address of the remote server, and the path to the repository. Depending
408 on the transport protocol, some of this information may be absent.
409
410 Git supports ssh, git, http, and https protocols (in addition, ftp and
411 ftps can be used for fetching, but this is inefficient and deprecated;
412 do not use them).
413
414 The native transport (i.e. git:// URL) does no authentication and
415 should be used with caution on unsecured networks.
416
417 The following syntaxes may be used with them:
418
419 • ssh://[user@]host.xz[:port]/path/to/repo.git/
420
421 • git://host.xz[:port]/path/to/repo.git/
422
423 • http[s]://host.xz[:port]/path/to/repo.git/
424
425 • ftp[s]://host.xz[:port]/path/to/repo.git/
426
427 An alternative scp-like syntax may also be used with the ssh protocol:
428
429 • [user@]host.xz:path/to/repo.git/
430
431 This syntax is only recognized if there are no slashes before the first
432 colon. This helps differentiate a local path that contains a colon. For
433 example the local path foo:bar could be specified as an absolute path
434 or ./foo:bar to avoid being misinterpreted as an ssh url.
435
436 The ssh and git protocols additionally support ~username expansion:
437
438 • ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
439
440 • git://host.xz[:port]/~[user]/path/to/repo.git/
441
442 • [user@]host.xz:/~[user]/path/to/repo.git/
443
444 For local repositories, also supported by Git natively, the following
445 syntaxes may be used:
446
447 • /path/to/repo.git/
448
449 • file:///path/to/repo.git/
450
451 These two syntaxes are mostly equivalent, except when cloning, when the
452 former implies --local option. See git-clone(1) for details.
453
454 git clone, git fetch and git pull, but not git push, will also accept a
455 suitable bundle file. See git-bundle(1).
456
457 When Git doesn’t know how to handle a certain transport protocol, it
458 attempts to use the remote-<transport> remote helper, if one exists. To
459 explicitly request a remote helper, the following syntax may be used:
460
461 • <transport>::<address>
462
463 where <address> may be a path, a server and path, or an arbitrary
464 URL-like string recognized by the specific remote helper being invoked.
465 See gitremote-helpers(7) for details.
466
467 If there are a large number of similarly-named remote repositories and
468 you want to use a different format for them (such that the URLs you use
469 will be rewritten into URLs that work), you can create a configuration
470 section of the form:
471
472 [url "<actual url base>"]
473 insteadOf = <other url base>
474
475 For example, with this:
476
477 [url "git://git.host.xz/"]
478 insteadOf = host.xz:/path/to/
479 insteadOf = work:
480
481 a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
482 rewritten in any context that takes a URL to be
483 "git://git.host.xz/repo.git".
484
485 If you want to rewrite URLs for push only, you can create a
486 configuration section of the form:
487
488 [url "<actual url base>"]
489 pushInsteadOf = <other url base>
490
491 For example, with this:
492
493 [url "ssh://example.org/"]
494 pushInsteadOf = git://example.org/
495
496 a URL like "git://example.org/path/to/repo.git" will be rewritten to
497 "ssh://example.org/path/to/repo.git" for pushes, but pulls will still
498 use the original URL.
499
501 The name of one of the following can be used instead of a URL as
502 <repository> argument:
503
504 • a remote in the Git configuration file: $GIT_DIR/config,
505
506 • a file in the $GIT_DIR/remotes directory, or
507
508 • a file in the $GIT_DIR/branches directory.
509
510 All of these also allow you to omit the refspec from the command line
511 because they each contain a refspec which git will use by default.
512
513 Named remote in configuration file
514 You can choose to provide the name of a remote which you had previously
515 configured using git-remote(1), git-config(1) or even by a manual edit
516 to the $GIT_DIR/config file. The URL of this remote will be used to
517 access the repository. The refspec of this remote will be used by
518 default when you do not provide a refspec on the command line. The
519 entry in the config file would appear like this:
520
521 [remote "<name>"]
522 url = <URL>
523 pushurl = <pushurl>
524 push = <refspec>
525 fetch = <refspec>
526
527 The <pushurl> is used for pushes only. It is optional and defaults to
528 <URL>. Pushing to a remote affects all defined pushurls or all defined
529 urls if no pushurls are defined. Fetch, however, will only fetch from
530 the first defined url if multiple urls are defined.
531
532 Named file in $GIT_DIR/remotes
533 You can choose to provide the name of a file in $GIT_DIR/remotes. The
534 URL in this file will be used to access the repository. The refspec in
535 this file will be used as default when you do not provide a refspec on
536 the command line. This file should have the following format:
537
538 URL: one of the above URL formats
539 Push: <refspec>
540 Pull: <refspec>
541
542 Push: lines are used by git push and Pull: lines are used by git pull
543 and git fetch. Multiple Push: and Pull: lines may be specified for
544 additional branch mappings.
545
546 Named file in $GIT_DIR/branches
547 You can choose to provide the name of a file in $GIT_DIR/branches. The
548 URL in this file will be used to access the repository. This file
549 should have the following format:
550
551 <URL>#<head>
552
553 <URL> is required; #<head> is optional.
554
555 Depending on the operation, git will use one of the following refspecs,
556 if you don’t provide one on the command line. <branch> is the name of
557 this file in $GIT_DIR/branches and <head> defaults to master.
558
559 git fetch uses:
560
561 refs/heads/<head>:refs/heads/<branch>
562
563 git push uses:
564
565 HEAD:refs/heads/<head>
566
568 The output of "git push" depends on the transport method used; this
569 section describes the output when pushing over the Git protocol (either
570 locally or via ssh).
571
572 The status of the push is output in tabular form, with each line
573 representing the status of a single ref. Each line is of the form:
574
575 <flag> <summary> <from> -> <to> (<reason>)
576
577 If --porcelain is used, then each line of the output is of the form:
578
579 <flag> \t <from>:<to> \t <summary> (<reason>)
580
581 The status of up-to-date refs is shown only if --porcelain or --verbose
582 option is used.
583
584 flag
585 A single character indicating the status of the ref:
586
587 (space)
588 for a successfully pushed fast-forward;
589
590 +
591 for a successful forced update;
592
593 -
594 for a successfully deleted ref;
595
596 *
597 for a successfully pushed new ref;
598
599 !
600 for a ref that was rejected or failed to push; and
601
602 =
603 for a ref that was up to date and did not need pushing.
604
605 summary
606 For a successfully pushed ref, the summary shows the old and new
607 values of the ref in a form suitable for using as an argument to
608 git log (this is <old>..<new> in most cases, and <old>...<new> for
609 forced non-fast-forward updates).
610
611 For a failed update, more details are given:
612
613 rejected
614 Git did not try to send the ref at all, typically because it is
615 not a fast-forward and you did not force the update.
616
617 remote rejected
618 The remote end refused the update. Usually caused by a hook on
619 the remote side, or because the remote repository has one of
620 the following safety options in effect:
621 receive.denyCurrentBranch (for pushes to the checked out
622 branch), receive.denyNonFastForwards (for forced
623 non-fast-forward updates), receive.denyDeletes or
624 receive.denyDeleteCurrent. See git-config(1).
625
626 remote failure
627 The remote end did not report the successful update of the ref,
628 perhaps because of a temporary error on the remote side, a
629 break in the network connection, or other transient error.
630
631 from
632 The name of the local ref being pushed, minus its refs/<type>/
633 prefix. In the case of deletion, the name of the local ref is
634 omitted.
635
636 to
637 The name of the remote ref being updated, minus its refs/<type>/
638 prefix.
639
640 reason
641 A human-readable explanation. In the case of successfully pushed
642 refs, no explanation is needed. For a failed ref, the reason for
643 failure is described.
644
646 When an update changes a branch (or more in general, a ref) that used
647 to point at commit A to point at another commit B, it is called a
648 fast-forward update if and only if B is a descendant of A.
649
650 In a fast-forward update from A to B, the set of commits that the
651 original commit A built on top of is a subset of the commits the new
652 commit B builds on top of. Hence, it does not lose any history.
653
654 In contrast, a non-fast-forward update will lose history. For example,
655 suppose you and somebody else started at the same commit X, and you
656 built a history leading to commit B while the other person built a
657 history leading to commit A. The history looks like this:
658
659 B
660 /
661 ---X---A
662
663 Further suppose that the other person already pushed changes leading to
664 A back to the original repository from which you two obtained the
665 original commit X.
666
667 The push done by the other person updated the branch that used to point
668 at commit X to point at commit A. It is a fast-forward.
669
670 But if you try to push, you will attempt to update the branch (that now
671 points at A) with commit B. This does not fast-forward. If you did so,
672 the changes introduced by commit A will be lost, because everybody will
673 now start building on top of B.
674
675 The command by default does not allow an update that is not a
676 fast-forward to prevent such loss of history.
677
678 If you do not want to lose your work (history from X to B) or the work
679 by the other person (history from X to A), you would need to first
680 fetch the history from the repository, create a history that contains
681 changes done by both parties, and push the result back.
682
683 You can perform "git pull", resolve potential conflicts, and "git push"
684 the result. A "git pull" will create a merge commit C between commits A
685 and B.
686
687 B---C
688 / /
689 ---X---A
690
691 Updating A with the resulting merge commit will fast-forward and your
692 push will be accepted.
693
694 Alternatively, you can rebase your change between X and B on top of A,
695 with "git pull --rebase", and push the result back. The rebase will
696 create a new commit D that builds the change between X and B on top of
697 A.
698
699 B D
700 / /
701 ---X---A
702
703 Again, updating A with this commit will fast-forward and your push will
704 be accepted.
705
706 There is another common situation where you may encounter
707 non-fast-forward rejection when you try to push, and it is possible
708 even when you are pushing into a repository nobody else pushes into.
709 After you push commit A yourself (in the first picture in this
710 section), replace it with "git commit --amend" to produce commit B, and
711 you try to push it out, because forgot that you have pushed A out
712 already. In such a case, and only if you are certain that nobody in the
713 meantime fetched your earlier commit A (and started building on top of
714 it), you can run "git push --force" to overwrite it. In other words,
715 "git push --force" is a method reserved for a case where you do mean to
716 lose history.
717
719 git push
720 Works like git push <remote>, where <remote> is the current
721 branch’s remote (or origin, if no remote is configured for the
722 current branch).
723
724 git push origin
725 Without additional configuration, pushes the current branch to the
726 configured upstream (branch.<name>.merge configuration variable) if
727 it has the same name as the current branch, and errors out without
728 pushing otherwise.
729
730 The default behavior of this command when no <refspec> is given can
731 be configured by setting the push option of the remote, or the
732 push.default configuration variable.
733
734 For example, to default to pushing only the current branch to
735 origin use git config remote.origin.push HEAD. Any valid <refspec>
736 (like the ones in the examples below) can be configured as the
737 default for git push origin.
738
739 git push origin :
740 Push "matching" branches to origin. See <refspec> in the OPTIONS
741 section above for a description of "matching" branches.
742
743 git push origin master
744 Find a ref that matches master in the source repository (most
745 likely, it would find refs/heads/master), and update the same ref
746 (e.g. refs/heads/master) in origin repository with it. If master
747 did not exist remotely, it would be created.
748
749 git push origin HEAD
750 A handy way to push the current branch to the same name on the
751 remote.
752
753 git push mothership master:satellite/master dev:satellite/dev
754 Use the source ref that matches master (e.g. refs/heads/master) to
755 update the ref that matches satellite/master (most probably
756 refs/remotes/satellite/master) in the mothership repository; do the
757 same for dev and satellite/dev.
758
759 See the section describing <refspec>... above for a discussion of
760 the matching semantics.
761
762 This is to emulate git fetch run on the mothership using git push
763 that is run in the opposite direction in order to integrate the
764 work done on satellite, and is often necessary when you can only
765 make connection in one way (i.e. satellite can ssh into mothership
766 but mothership cannot initiate connection to satellite because the
767 latter is behind a firewall or does not run sshd).
768
769 After running this git push on the satellite machine, you would ssh
770 into the mothership and run git merge there to complete the
771 emulation of git pull that were run on mothership to pull changes
772 made on satellite.
773
774 git push origin HEAD:master
775 Push the current branch to the remote ref matching master in the
776 origin repository. This form is convenient to push the current
777 branch without thinking about its local name.
778
779 git push origin master:refs/heads/experimental
780 Create the branch experimental in the origin repository by copying
781 the current master branch. This form is only needed to create a new
782 branch or tag in the remote repository when the local name and the
783 remote name are different; otherwise, the ref name on its own will
784 work.
785
786 git push origin :experimental
787 Find a ref that matches experimental in the origin repository (e.g.
788 refs/heads/experimental), and delete it.
789
790 git push origin +dev:master
791 Update the origin repository’s master branch with the dev branch,
792 allowing non-fast-forward updates. This can leave unreferenced
793 commits dangling in the origin repository. Consider the following
794 situation, where a fast-forward is not possible:
795
796 o---o---o---A---B origin/master
797 \
798 X---Y---Z dev
799
800 The above command would change the origin repository to
801
802 A---B (unnamed branch)
803 /
804 o---o---o---X---Y---Z master
805
806 Commits A and B would no longer belong to a branch with a symbolic
807 name, and so would be unreachable. As such, these commits would be
808 removed by a git gc command on the origin repository.
809
811 The fetch and push protocols are not designed to prevent one side from
812 stealing data from the other repository that was not intended to be
813 shared. If you have private data that you need to protect from a
814 malicious peer, your best option is to store it in another repository.
815 This applies to both clients and servers. In particular, namespaces on
816 a server are not effective for read access control; you should only
817 grant read access to a namespace to clients that you would trust with
818 read access to the entire repository.
819
820 The known attack vectors are as follows:
821
822 1. The victim sends "have" lines advertising the IDs of objects it has
823 that are not explicitly intended to be shared but can be used to
824 optimize the transfer if the peer also has them. The attacker
825 chooses an object ID X to steal and sends a ref to X, but isn’t
826 required to send the content of X because the victim already has
827 it. Now the victim believes that the attacker has X, and it sends
828 the content of X back to the attacker later. (This attack is most
829 straightforward for a client to perform on a server, by creating a
830 ref to X in the namespace the client has access to and then
831 fetching it. The most likely way for a server to perform it on a
832 client is to "merge" X into a public branch and hope that the user
833 does additional work on this branch and pushes it back to the
834 server without noticing the merge.)
835
836 2. As in #1, the attacker chooses an object ID X to steal. The victim
837 sends an object Y that the attacker already has, and the attacker
838 falsely claims to have X and not Y, so the victim sends Y as a
839 delta against X. The delta reveals regions of X that are similar to
840 Y to the attacker.
841
843 Everything below this line in this section is selectively included from
844 the git-config(1) documentation. The content is the same as what’s
845 found there:
846
847 push.autoSetupRemote
848 If set to "true" assume --set-upstream on default push when no
849 upstream tracking exists for the current branch; this option takes
850 effect with push.default options simple, upstream, and current. It
851 is useful if by default you want new branches to be pushed to the
852 default remote (like the behavior of push.default=current) and you
853 also want the upstream tracking to be set. Workflows most likely to
854 benefit from this option are simple central workflows where all
855 branches are expected to have the same name on the remote.
856
857 push.default
858 Defines the action git push should take if no refspec is given
859 (whether from the command-line, config, or elsewhere). Different
860 values are well-suited for specific workflows; for instance, in a
861 purely central workflow (i.e. the fetch source is equal to the push
862 destination), upstream is probably what you want. Possible values
863 are:
864
865 • nothing - do not push anything (error out) unless a refspec is
866 given. This is primarily meant for people who want to avoid
867 mistakes by always being explicit.
868
869 • current - push the current branch to update a branch with the
870 same name on the receiving end. Works in both central and
871 non-central workflows.
872
873 • upstream - push the current branch back to the branch whose
874 changes are usually integrated into the current branch (which
875 is called @{upstream}). This mode only makes sense if you are
876 pushing to the same repository you would normally pull from
877 (i.e. central workflow).
878
879 • tracking - This is a deprecated synonym for upstream.
880
881 • simple - push the current branch with the same name on the
882 remote.
883
884 If you are working on a centralized workflow (pushing to the
885 same repository you pull from, which is typically origin), then
886 you need to configure an upstream branch with the same name.
887
888 This mode is the default since Git 2.0, and is the safest
889 option suited for beginners.
890
891 • matching - push all branches having the same name on both ends.
892 This makes the repository you are pushing to remember the set
893 of branches that will be pushed out (e.g. if you always push
894 maint and master there and no other branches, the repository
895 you push to will have these two branches, and your local maint
896 and master will be pushed there).
897
898 To use this mode effectively, you have to make sure all the
899 branches you would push out are ready to be pushed out before
900 running git push, as the whole point of this mode is to allow
901 you to push all of the branches in one go. If you usually
902 finish work on only one branch and push out the result, while
903 other branches are unfinished, this mode is not for you. Also
904 this mode is not suitable for pushing into a shared central
905 repository, as other people may add new branches there, or
906 update the tip of existing branches outside your control.
907
908 This used to be the default, but not since Git 2.0 (simple is
909 the new default).
910
911 push.followTags
912 If set to true, enable --follow-tags option by default. You may
913 override this configuration at time of push by specifying
914 --no-follow-tags.
915
916 push.gpgSign
917 May be set to a boolean value, or the string if-asked. A true value
918 causes all pushes to be GPG signed, as if --signed is passed to
919 git-push(1). The string if-asked causes pushes to be signed if the
920 server supports it, as if --signed=if-asked is passed to git push.
921 A false value may override a value from a lower-priority config
922 file. An explicit command-line flag always overrides this config
923 option.
924
925 push.pushOption
926 When no --push-option=<option> argument is given from the command
927 line, git push behaves as if each <value> of this variable is given
928 as --push-option=<value>.
929
930 This is a multi-valued variable, and an empty value can be used in
931 a higher priority configuration file (e.g. .git/config in a
932 repository) to clear the values inherited from a lower priority
933 configuration files (e.g. $HOME/.gitconfig).
934
935 Example:
936
937 /etc/gitconfig
938 push.pushoption = a
939 push.pushoption = b
940
941 ~/.gitconfig
942 push.pushoption = c
943
944 repo/.git/config
945 push.pushoption =
946 push.pushoption = b
947
948 This will result in only b (a and c are cleared).
949
950 push.recurseSubmodules
951 May be "check", "on-demand", "only", or "no", with the same
952 behavior as that of "push --recurse-submodules". If not set, no is
953 used by default, unless submodule.recurse is set (in which case a
954 true value means on-demand).
955
956 push.useForceIfIncludes
957 If set to "true", it is equivalent to specifying
958 --force-if-includes as an option to git-push(1) in the command
959 line. Adding --no-force-if-includes at the time of push overrides
960 this configuration setting.
961
962 push.negotiate
963 If set to "true", attempt to reduce the size of the packfile sent
964 by rounds of negotiation in which the client and the server attempt
965 to find commits in common. If "false", Git will rely solely on the
966 server’s ref advertisement to find commits in common.
967
968 push.useBitmaps
969 If set to "false", disable use of bitmaps for "git push" even if
970 pack.useBitmaps is "true", without preventing other git operations
971 from using bitmaps. Default is true.
972
974 Part of the git(1) suite
975
976
977
978Git 2.43.0 11/20/2023 GIT-PUSH(1)