1GIT-PUSH(1)                       Git Manual                       GIT-PUSH(1)
2
3
4

NAME

6       git-push - Update remote refs along with associated objects
7

SYNOPSIS

9       git push [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
10                  [--repo=<repository>] [-f | --force] [-d | --delete] [--prune] [-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

DESCRIPTION

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 specify 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

OPTIONS

43       <repository>
44           The "remote" repository that is destination of a push operation.
45           This parameter can be either a URL (see the section GIT URLS below)
46           or the name of a remote (see the section REMOTES below).
47
48       <refspec>...
49           Specify what destination ref to update with what source object. The
50           format of a <refspec> parameter is an optional plus +, followed by
51           the source object <src>, followed by a colon :, followed by the
52           destination ref <dst>.
53
54           The <src> is often the name of the branch you would want to push,
55           but it can be any arbitrary "SHA-1 expression", such as master~4 or
56           HEAD (see gitrevisions(7)).
57
58           The <dst> tells which ref on the remote side is updated with this
59           push. Arbitrary expressions cannot be used here, an actual ref must
60           be named. If git push [<repository>] without any <refspec> argument
61           is set to update some ref at the destination with <src> with
62           remote.<repository>.push configuration variable, :<dst> part can be
63           omitted—such a push will update a ref that <src> normally updates
64           without any <refspec> on the command line. Otherwise, missing
65           :<dst> means to update the same ref as the <src>.
66
67           If <dst> doesn’t start with refs/ (e.g.  refs/heads/master) we will
68           try to infer where in refs/* on the destination <repository> it
69           belongs based on the type of <src> being pushed and whether <dst>
70           is ambiguous.
71
72           •   If <dst> unambiguously refers to a ref on the <repository>
73               remote, then push to that ref.
74
75           •   If <src> resolves to a ref starting with refs/heads/ or
76               refs/tags/, then prepend that to <dst>.
77
78           •   Other ambiguity resolutions might be added in the future, but
79               for now any other cases will error out with an error indicating
80               what we tried, and depending on the
81               advice.pushUnqualifiedRefname configuration (see git-config(1))
82               suggest what refs/ namespace you may have wanted to push to.
83
84           The object referenced by <src> is used to update the <dst>
85           reference on the remote side. Whether this is allowed depends on
86           where in refs/* the <dst> reference lives as described in detail
87           below, in those sections "update" means any modifications except
88           deletes, which as noted after the next few sections are treated
89           differently.
90
91           The refs/heads/* namespace will only accept commit objects, and
92           updates only if they can be fast-forwarded.
93
94           The refs/tags/* namespace will accept any kind of object (as
95           commits, trees and blobs can be tagged), and any updates to them
96           will be rejected.
97
98           It’s possible to push any type of object to any namespace outside
99           of refs/{tags,heads}/*. In the case of tags and commits, these will
100           be treated as if they were the commits inside refs/heads/* for the
101           purposes of whether the update is allowed.
102
103           I.e. a fast-forward of commits and tags outside refs/{tags,heads}/*
104           is allowed, even in cases where what’s being fast-forwarded is not
105           a commit, but a tag object which happens to point to a new commit
106           which is a fast-forward of the commit the last tag (or commit) it’s
107           replacing. Replacing a tag with an entirely different tag is also
108           allowed, if it points to the same commit, as well as pushing a
109           peeled tag, i.e. pushing the commit that existing tag object points
110           to, or a new tag object which an existing commit points to.
111
112           Tree and blob objects outside of refs/{tags,heads}/* will be
113           treated the same way as if they were inside refs/tags/*, any update
114           of them will be rejected.
115
116           All of the rules described above about what’s not allowed as an
117           update can be overridden by adding an the optional leading + to a
118           refspec (or using --force command line option). The only exception
119           to this is that no amount of forcing will make the refs/heads/*
120           namespace accept a non-commit object. Hooks and configuration can
121           also override or amend these rules, see e.g.
122           receive.denyNonFastForwards in git-config(1) and pre-receive and
123           update in githooks(5).
124
125           Pushing an empty <src> allows you to delete the <dst> ref from the
126           remote repository. Deletions are always accepted without a leading
127           + in the refspec (or --force), except when forbidden by
128           configuration or hooks. See receive.denyDeletes in git-config(1)
129           and pre-receive and update in githooks(5).
130
131           The special refspec : (or +: to allow non-fast-forward updates)
132           directs Git to push "matching" branches: for every branch that
133           exists on the local side, the remote side is updated if a branch of
134           the same name already exists on the remote side.
135
136           tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>.
137
138       --all
139           Push all branches (i.e. refs under refs/heads/); cannot be used
140           with other <refspec>.
141
142       --prune
143           Remove remote branches that don’t have a local counterpart. For
144           example a remote branch tmp will be removed if a local branch with
145           the same name doesn’t exist any more. This also respects refspecs,
146           e.g.  git push --prune remote refs/heads/*:refs/tmp/* would make
147           sure that remote refs/tmp/foo will be removed if refs/heads/foo
148           doesn’t exist.
149
150       --mirror
151           Instead of naming each ref to push, specifies that all refs under
152           refs/ (which includes but is not limited to refs/heads/,
153           refs/remotes/, and refs/tags/) be mirrored to the remote
154           repository. Newly created local refs will be pushed to the remote
155           end, locally updated refs will be force updated on the remote end,
156           and deleted refs will be removed from the remote end. This is the
157           default if the configuration option remote.<remote>.mirror is set.
158
159       -n, --dry-run
160           Do everything except actually send the updates.
161
162       --porcelain
163           Produce machine-readable output. The output status line for each
164           ref will be tab-separated and sent to stdout instead of stderr. The
165           full symbolic names of the refs will be given.
166
167       -d, --delete
168           All listed refs are deleted from the remote repository. This is the
169           same as prefixing all refs with a colon.
170
171       --tags
172           All refs under refs/tags are pushed, in addition to refspecs
173           explicitly listed on the command line.
174
175       --follow-tags
176           Push all the refs that would be pushed without this option, and
177           also push annotated tags in refs/tags that are missing from the
178           remote but are pointing at commit-ish that are reachable from the
179           refs being pushed. This can also be specified with configuration
180           variable push.followTags. For more information, see push.followTags
181           in git-config(1).
182
183       --[no-]signed, --signed=(true|false|if-asked)
184           GPG-sign the push request to update refs on the receiving side, to
185           allow it to be checked by the hooks and/or be logged. If false or
186           --no-signed, no signing will be attempted. If true or --signed, the
187           push will fail if the server does not support signed pushes. If set
188           to if-asked, sign if and only if the server supports signed pushes.
189           The push will also fail if the actual call to gpg --sign fails. See
190           git-receive-pack(1) for the details on the receiving end.
191
192       --[no-]atomic
193           Use an atomic transaction on the remote side if available. Either
194           all refs are updated, or on error, no refs are updated. If the
195           server does not support atomic pushes the push will fail.
196
197       -o <option>, --push-option=<option>
198           Transmit the given string to the server, which passes them to the
199           pre-receive as well as the post-receive hook. The given string must
200           not contain a NUL or LF character. When multiple
201           --push-option=<option> are given, they are all sent to the other
202           side in the order listed on the command line. When no
203           --push-option=<option> is given from the command line, the values
204           of configuration variable push.pushOption are used instead.
205
206       --receive-pack=<git-receive-pack>, --exec=<git-receive-pack>
207           Path to the git-receive-pack program on the remote end. Sometimes
208           useful when pushing to a remote repository over ssh, and you do not
209           have the program in a directory on the default $PATH.
210
211       --[no-]force-with-lease, --force-with-lease=<refname>,
212       --force-with-lease=<refname>:<expect>
213           Usually, "git push" refuses to update a remote ref that is not an
214           ancestor of the local ref used to overwrite it.
215
216           This option overrides this restriction if the current value of the
217           remote ref is the expected value. "git push" fails otherwise.
218
219           Imagine that you have to rebase what you have already published.
220           You will have to bypass the "must fast-forward" rule in order to
221           replace the history you originally published with the rebased
222           history. If somebody else built on top of your original history
223           while you are rebasing, the tip of the branch at the remote may
224           advance with their commit, and blindly pushing with --force will
225           lose their work.
226
227           This option allows you to say that you expect the history you are
228           updating is what you rebased and want to replace. If the remote ref
229           still points at the commit you specified, you can be sure that no
230           other people did anything to the ref. It is like taking a "lease"
231           on the ref without explicitly locking it, and the remote ref is
232           updated only if the "lease" is still valid.
233
234           --force-with-lease alone, without specifying the details, will
235           protect all remote refs that are going to be updated by requiring
236           their current value to be the same as the remote-tracking branch we
237           have for them.
238
239           --force-with-lease=<refname>, without specifying the expected
240           value, will protect the named ref (alone), if it is going to be
241           updated, by requiring its current value to be the same as the
242           remote-tracking branch we have for it.
243
244           --force-with-lease=<refname>:<expect> will protect the named ref
245           (alone), if it is going to be updated, by requiring its current
246           value to be the same as the specified value <expect> (which is
247           allowed to be different from the remote-tracking branch we have for
248           the refname, or we do not even have to have such a remote-tracking
249           branch when this form is used). If <expect> is the empty string,
250           then the named ref must not already exist.
251
252           Note that all forms other than
253           --force-with-lease=<refname>:<expect> that specifies the expected
254           current value of the ref explicitly are still experimental and
255           their semantics may change as we gain experience with this feature.
256
257           "--no-force-with-lease" will cancel all the previous
258           --force-with-lease on the command line.
259
260           A general note on safety: supplying this option without an expected
261           value, i.e. as --force-with-lease or --force-with-lease=<refname>
262           interacts very badly with anything that implicitly runs git fetch
263           on the remote to be pushed to in the background, e.g.  git fetch
264           origin on your repository in a cronjob.
265
266           The protection it offers over --force is ensuring that subsequent
267           changes your work wasn’t based on aren’t clobbered, but this is
268           trivially defeated if some background process is updating refs in
269           the background. We don’t have anything except the remote tracking
270           info to go by as a heuristic for refs you’re expected to have seen
271           & are willing to clobber.
272
273           If your editor or some other system is running git fetch in the
274           background for you a way to mitigate this is to simply set up
275           another remote:
276
277               git remote add origin-push $(git config remote.origin.url)
278               git fetch origin-push
279
280           Now when the background process runs git fetch origin the
281           references on origin-push won’t be updated, and thus commands like:
282
283               git push --force-with-lease origin-push
284
285           Will fail unless you manually run git fetch origin-push. This
286           method is of course entirely defeated by something that runs git
287           fetch --all, in that case you’d need to either disable it or do
288           something more tedious like:
289
290               git fetch              # update 'master' from remote
291               git tag base master    # mark our base point
292               git rebase -i master   # rewrite some commits
293               git push --force-with-lease=master:base master:master
294
295           I.e. create a base tag for versions of the upstream code that
296           you’ve seen and are willing to overwrite, then rewrite history, and
297           finally force push changes to master if the remote version is still
298           at base, regardless of what your local remotes/origin/master has
299           been updated to in the background.
300
301           Alternatively, specifying --force-if-includes as an ancillary
302           option along with --force-with-lease[=<refname>] (i.e., without
303           saying what exact commit the ref on the remote side must be
304           pointing at, or which refs on the remote side are being protected)
305           at the time of "push" will verify if updates from the
306           remote-tracking refs that may have been implicitly updated in the
307           background are integrated locally before allowing a forced update.
308
309       -f, --force
310           Usually, the command refuses to update a remote ref that is not an
311           ancestor of the local ref used to overwrite it. Also, when
312           --force-with-lease option is used, the command refuses to update a
313           remote ref whose current value does not match what is expected.
314
315           This flag disables these checks, and can cause the remote
316           repository to lose commits; use it with care.
317
318           Note that --force applies to all the refs that are pushed, hence
319           using it with push.default set to matching or with multiple push
320           destinations configured with remote.*.push may overwrite refs other
321           than the current branch (including local refs that are strictly
322           behind their remote counterpart). To force a push to only one
323           branch, use a + in front of the refspec to push (e.g git push
324           origin +master to force a push to the master branch). See the
325           <refspec>...  section above for details.
326
327       --[no-]force-if-includes
328           Force an update only if the tip of the remote-tracking ref has been
329           integrated locally.
330
331           This option enables a check that verifies if the tip of the
332           remote-tracking ref is reachable from one of the "reflog" entries
333           of the local branch based in it for a rewrite. The check ensures
334           that any updates from the remote have been incorporated locally by
335           rejecting the forced update if that is not the case.
336
337           If the option is passed without specifying --force-with-lease, or
338           specified along with --force-with-lease=<refname>:<expect>, it is a
339           "no-op".
340
341           Specifying --no-force-if-includes disables this behavior.
342
343       --repo=<repository>
344           This option is equivalent to the <repository> argument. If both are
345           specified, the command-line argument takes precedence.
346
347       -u, --set-upstream
348           For every branch that is up to date or successfully pushed, add
349           upstream (tracking) reference, used by argument-less git-pull(1)
350           and other commands. For more information, see branch.<name>.merge
351           in git-config(1).
352
353       --[no-]thin
354           These options are passed to git-send-pack(1). A thin transfer
355           significantly reduces the amount of sent data when the sender and
356           receiver share many of the same objects in common. The default is
357           --thin.
358
359       -q, --quiet
360           Suppress all output, including the listing of updated refs, unless
361           an error occurs. Progress is not reported to the standard error
362           stream.
363
364       -v, --verbose
365           Run verbosely.
366
367       --progress
368           Progress status is reported on the standard error stream by default
369           when it is attached to a terminal, unless -q is specified. This
370           flag forces progress status even if the standard error stream is
371           not directed to a terminal.
372
373       --no-recurse-submodules, --recurse-submodules=check|on-demand|only|no
374           May be used to make sure all submodule commits used by the
375           revisions to be pushed are available on a remote-tracking branch.
376           If check is used Git will verify that all submodule commits that
377           changed in the revisions to be pushed are available on at least one
378           remote of the submodule. If any commits are missing the push will
379           be aborted and exit with non-zero status. If on-demand is used all
380           submodules that changed in the revisions to be pushed will be
381           pushed. If on-demand was not able to push all necessary revisions
382           it will also be aborted and exit with non-zero status. If only is
383           used all submodules will be pushed while the superproject is left
384           unpushed. A value of no or using --no-recurse-submodules can be
385           used to override the push.recurseSubmodules configuration variable
386           when no submodule recursion is required.
387
388           When using on-demand or only, if a submodule has a
389           "push.recurseSubmodules={on-demand,only}" or "submodule.recurse"
390           configuration, further recursion will occur. In this case, "only"
391           is treated as "on-demand".
392
393       --[no-]verify
394           Toggle the pre-push hook (see githooks(5)). The default is
395           --verify, giving the hook a chance to prevent the push. With
396           --no-verify, the hook is bypassed completely.
397
398       -4, --ipv4
399           Use IPv4 addresses only, ignoring IPv6 addresses.
400
401       -6, --ipv6
402           Use IPv6 addresses only, ignoring IPv4 addresses.
403

GIT URLS

405       In general, URLs contain information about the transport protocol, the
406       address of the remote server, and the path to the repository. Depending
407       on the transport protocol, some of this information may be absent.
408
409       Git supports ssh, git, http, and https protocols (in addition, ftp, and
410       ftps can be used for fetching, but this is inefficient and deprecated;
411       do not use it).
412
413       The native transport (i.e. git:// URL) does no authentication and
414       should be used with caution on unsecured networks.
415
416       The following syntaxes may be used with them:
417
418       •   ssh://[user@]host.xz[:port]/path/to/repo.git/
419
420       •   git://host.xz[:port]/path/to/repo.git/
421
422       •   http[s]://host.xz[:port]/path/to/repo.git/
423
424       •   ftp[s]://host.xz[:port]/path/to/repo.git/
425
426       An alternative scp-like syntax may also be used with the ssh protocol:
427
428       •   [user@]host.xz:path/to/repo.git/
429
430       This syntax is only recognized if there are no slashes before the first
431       colon. This helps differentiate a local path that contains a colon. For
432       example the local path foo:bar could be specified as an absolute path
433       or ./foo:bar to avoid being misinterpreted as an ssh url.
434
435       The ssh and git protocols additionally support ~username expansion:
436
437       •   ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
438
439       •   git://host.xz[:port]/~[user]/path/to/repo.git/
440
441       •   [user@]host.xz:/~[user]/path/to/repo.git/
442
443       For local repositories, also supported by Git natively, the following
444       syntaxes may be used:
445
446       •   /path/to/repo.git/
447
448       •   file:///path/to/repo.git/
449
450       These two syntaxes are mostly equivalent, except when cloning, when the
451       former implies --local option. See git-clone(1) for details.
452
453       git clone, git fetch and git pull, but not git push, will also accept a
454       suitable bundle file. See git-bundle(1).
455
456       When Git doesn’t know how to handle a certain transport protocol, it
457       attempts to use the remote-<transport> remote helper, if one exists. To
458       explicitly request a remote helper, the following syntax may be used:
459
460       •   <transport>::<address>
461
462       where <address> may be a path, a server and path, or an arbitrary
463       URL-like string recognized by the specific remote helper being invoked.
464       See gitremote-helpers(7) for details.
465
466       If there are a large number of similarly-named remote repositories and
467       you want to use a different format for them (such that the URLs you use
468       will be rewritten into URLs that work), you can create a configuration
469       section of the form:
470
471                   [url "<actual url base>"]
472                           insteadOf = <other url base>
473
474       For example, with this:
475
476                   [url "git://git.host.xz/"]
477                           insteadOf = host.xz:/path/to/
478                           insteadOf = work:
479
480       a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
481       rewritten in any context that takes a URL to be
482       "git://git.host.xz/repo.git".
483
484       If you want to rewrite URLs for push only, you can create a
485       configuration section of the form:
486
487                   [url "<actual url base>"]
488                           pushInsteadOf = <other url base>
489
490       For example, with this:
491
492                   [url "ssh://example.org/"]
493                           pushInsteadOf = git://example.org/
494
495       a URL like "git://example.org/path/to/repo.git" will be rewritten to
496       "ssh://example.org/path/to/repo.git" for pushes, but pulls will still
497       use the original URL.
498

REMOTES

500       The name of one of the following can be used instead of a URL as
501       <repository> argument:
502
503       •   a remote in the Git configuration file: $GIT_DIR/config,
504
505       •   a file in the $GIT_DIR/remotes directory, or
506
507       •   a file in the $GIT_DIR/branches directory.
508
509       All of these also allow you to omit the refspec from the command line
510       because they each contain a refspec which git will use by default.
511
512   Named remote in configuration file
513       You can choose to provide the name of a remote which you had previously
514       configured using git-remote(1), git-config(1) or even by a manual edit
515       to the $GIT_DIR/config file. The URL of this remote will be used to
516       access the repository. The refspec of this remote will be used by
517       default when you do not provide a refspec on the command line. The
518       entry in the config file would appear like this:
519
520                   [remote "<name>"]
521                           url = <URL>
522                           pushurl = <pushurl>
523                           push = <refspec>
524                           fetch = <refspec>
525
526       The <pushurl> is used for pushes only. It is optional and defaults to
527       <URL>.
528
529   Named file in $GIT_DIR/remotes
530       You can choose to provide the name of a file in $GIT_DIR/remotes. The
531       URL in this file will be used to access the repository. The refspec in
532       this file will be used as default when you do not provide a refspec on
533       the command line. This file should have the following format:
534
535                   URL: one of the above URL format
536                   Push: <refspec>
537                   Pull: <refspec>
538
539       Push: lines are used by git push and Pull: lines are used by git pull
540       and git fetch. Multiple Push: and Pull: lines may be specified for
541       additional branch mappings.
542
543   Named file in $GIT_DIR/branches
544       You can choose to provide the name of a file in $GIT_DIR/branches. The
545       URL in this file will be used to access the repository. This file
546       should have the following format:
547
548                   <URL>#<head>
549
550       <URL> is required; #<head> is optional.
551
552       Depending on the operation, git will use one of the following refspecs,
553       if you don’t provide one on the command line. <branch> is the name of
554       this file in $GIT_DIR/branches and <head> defaults to master.
555
556       git fetch uses:
557
558                   refs/heads/<head>:refs/heads/<branch>
559
560       git push uses:
561
562                   HEAD:refs/heads/<head>
563

OUTPUT

565       The output of "git push" depends on the transport method used; this
566       section describes the output when pushing over the Git protocol (either
567       locally or via ssh).
568
569       The status of the push is output in tabular form, with each line
570       representing the status of a single ref. Each line is of the form:
571
572            <flag> <summary> <from> -> <to> (<reason>)
573
574       If --porcelain is used, then each line of the output is of the form:
575
576            <flag> \t <from>:<to> \t <summary> (<reason>)
577
578       The status of up-to-date refs is shown only if --porcelain or --verbose
579       option is used.
580
581       flag
582           A single character indicating the status of the ref:
583
584           (space)
585               for a successfully pushed fast-forward;
586
587           +
588               for a successful forced update;
589
590           -
591               for a successfully deleted ref;
592
593           *
594               for a successfully pushed new ref;
595
596           !
597               for a ref that was rejected or failed to push; and
598
599           =
600               for a ref that was up to date and did not need pushing.
601
602       summary
603           For a successfully pushed ref, the summary shows the old and new
604           values of the ref in a form suitable for using as an argument to
605           git log (this is <old>..<new> in most cases, and <old>...<new> for
606           forced non-fast-forward updates).
607
608           For a failed update, more details are given:
609
610           rejected
611               Git did not try to send the ref at all, typically because it is
612               not a fast-forward and you did not force the update.
613
614           remote rejected
615               The remote end refused the update. Usually caused by a hook on
616               the remote side, or because the remote repository has one of
617               the following safety options in effect:
618               receive.denyCurrentBranch (for pushes to the checked out
619               branch), receive.denyNonFastForwards (for forced
620               non-fast-forward updates), receive.denyDeletes or
621               receive.denyDeleteCurrent. See git-config(1).
622
623           remote failure
624               The remote end did not report the successful update of the ref,
625               perhaps because of a temporary error on the remote side, a
626               break in the network connection, or other transient error.
627
628       from
629           The name of the local ref being pushed, minus its refs/<type>/
630           prefix. In the case of deletion, the name of the local ref is
631           omitted.
632
633       to
634           The name of the remote ref being updated, minus its refs/<type>/
635           prefix.
636
637       reason
638           A human-readable explanation. In the case of successfully pushed
639           refs, no explanation is needed. For a failed ref, the reason for
640           failure is described.
641

NOTE ABOUT FAST-FORWARDS

643       When an update changes a branch (or more in general, a ref) that used
644       to point at commit A to point at another commit B, it is called a
645       fast-forward update if and only if B is a descendant of A.
646
647       In a fast-forward update from A to B, the set of commits that the
648       original commit A built on top of is a subset of the commits the new
649       commit B builds on top of. Hence, it does not lose any history.
650
651       In contrast, a non-fast-forward update will lose history. For example,
652       suppose you and somebody else started at the same commit X, and you
653       built a history leading to commit B while the other person built a
654       history leading to commit A. The history looks like this:
655
656                 B
657                /
658            ---X---A
659
660       Further suppose that the other person already pushed changes leading to
661       A back to the original repository from which you two obtained the
662       original commit X.
663
664       The push done by the other person updated the branch that used to point
665       at commit X to point at commit A. It is a fast-forward.
666
667       But if you try to push, you will attempt to update the branch (that now
668       points at A) with commit B. This does not fast-forward. If you did so,
669       the changes introduced by commit A will be lost, because everybody will
670       now start building on top of B.
671
672       The command by default does not allow an update that is not a
673       fast-forward to prevent such loss of history.
674
675       If you do not want to lose your work (history from X to B) or the work
676       by the other person (history from X to A), you would need to first
677       fetch the history from the repository, create a history that contains
678       changes done by both parties, and push the result back.
679
680       You can perform "git pull", resolve potential conflicts, and "git push"
681       the result. A "git pull" will create a merge commit C between commits A
682       and B.
683
684                 B---C
685                /   /
686            ---X---A
687
688       Updating A with the resulting merge commit will fast-forward and your
689       push will be accepted.
690
691       Alternatively, you can rebase your change between X and B on top of A,
692       with "git pull --rebase", and push the result back. The rebase will
693       create a new commit D that builds the change between X and B on top of
694       A.
695
696                 B   D
697                /   /
698            ---X---A
699
700       Again, updating A with this commit will fast-forward and your push will
701       be accepted.
702
703       There is another common situation where you may encounter
704       non-fast-forward rejection when you try to push, and it is possible
705       even when you are pushing into a repository nobody else pushes into.
706       After you push commit A yourself (in the first picture in this
707       section), replace it with "git commit --amend" to produce commit B, and
708       you try to push it out, because forgot that you have pushed A out
709       already. In such a case, and only if you are certain that nobody in the
710       meantime fetched your earlier commit A (and started building on top of
711       it), you can run "git push --force" to overwrite it. In other words,
712       "git push --force" is a method reserved for a case where you do mean to
713       lose history.
714

EXAMPLES

716       git push
717           Works like git push <remote>, where <remote> is the current
718           branch’s remote (or origin, if no remote is configured for the
719           current branch).
720
721       git push origin
722           Without additional configuration, pushes the current branch to the
723           configured upstream (branch.<name>.merge configuration variable) if
724           it has the same name as the current branch, and errors out without
725           pushing otherwise.
726
727           The default behavior of this command when no <refspec> is given can
728           be configured by setting the push option of the remote, or the
729           push.default configuration variable.
730
731           For example, to default to pushing only the current branch to
732           origin use git config remote.origin.push HEAD. Any valid <refspec>
733           (like the ones in the examples below) can be configured as the
734           default for git push origin.
735
736       git push origin :
737           Push "matching" branches to origin. See <refspec> in the OPTIONS
738           section above for a description of "matching" branches.
739
740       git push origin master
741           Find a ref that matches master in the source repository (most
742           likely, it would find refs/heads/master), and update the same ref
743           (e.g.  refs/heads/master) in origin repository with it. If master
744           did not exist remotely, it would be created.
745
746       git push origin HEAD
747           A handy way to push the current branch to the same name on the
748           remote.
749
750       git push mothership master:satellite/master dev:satellite/dev
751           Use the source ref that matches master (e.g.  refs/heads/master) to
752           update the ref that matches satellite/master (most probably
753           refs/remotes/satellite/master) in the mothership repository; do the
754           same for dev and satellite/dev.
755
756           See the section describing <refspec>...  above for a discussion of
757           the matching semantics.
758
759           This is to emulate git fetch run on the mothership using git push
760           that is run in the opposite direction in order to integrate the
761           work done on satellite, and is often necessary when you can only
762           make connection in one way (i.e. satellite can ssh into mothership
763           but mothership cannot initiate connection to satellite because the
764           latter is behind a firewall or does not run sshd).
765
766           After running this git push on the satellite machine, you would ssh
767           into the mothership and run git merge there to complete the
768           emulation of git pull that were run on mothership to pull changes
769           made on satellite.
770
771       git push origin HEAD:master
772           Push the current branch to the remote ref matching master in the
773           origin repository. This form is convenient to push the current
774           branch without thinking about its local name.
775
776       git push origin master:refs/heads/experimental
777           Create the branch experimental in the origin repository by copying
778           the current master branch. This form is only needed to create a new
779           branch or tag in the remote repository when the local name and the
780           remote name are different; otherwise, the ref name on its own will
781           work.
782
783       git push origin :experimental
784           Find a ref that matches experimental in the origin repository (e.g.
785           refs/heads/experimental), and delete it.
786
787       git push origin +dev:master
788           Update the origin repository’s master branch with the dev branch,
789           allowing non-fast-forward updates.  This can leave unreferenced
790           commits dangling in the origin repository.  Consider the following
791           situation, where a fast-forward is not possible:
792
793                           o---o---o---A---B  origin/master
794                                    \
795                                     X---Y---Z  dev
796
797           The above command would change the origin repository to
798
799                                     A---B  (unnamed branch)
800                                    /
801                           o---o---o---X---Y---Z  master
802
803           Commits A and B would no longer belong to a branch with a symbolic
804           name, and so would be unreachable. As such, these commits would be
805           removed by a git gc command on the origin repository.
806

SECURITY

808       The fetch and push protocols are not designed to prevent one side from
809       stealing data from the other repository that was not intended to be
810       shared. If you have private data that you need to protect from a
811       malicious peer, your best option is to store it in another repository.
812       This applies to both clients and servers. In particular, namespaces on
813       a server are not effective for read access control; you should only
814       grant read access to a namespace to clients that you would trust with
815       read access to the entire repository.
816
817       The known attack vectors are as follows:
818
819        1. The victim sends "have" lines advertising the IDs of objects it has
820           that are not explicitly intended to be shared but can be used to
821           optimize the transfer if the peer also has them. The attacker
822           chooses an object ID X to steal and sends a ref to X, but isn’t
823           required to send the content of X because the victim already has
824           it. Now the victim believes that the attacker has X, and it sends
825           the content of X back to the attacker later. (This attack is most
826           straightforward for a client to perform on a server, by creating a
827           ref to X in the namespace the client has access to and then
828           fetching it. The most likely way for a server to perform it on a
829           client is to "merge" X into a public branch and hope that the user
830           does additional work on this branch and pushes it back to the
831           server without noticing the merge.)
832
833        2. As in #1, the attacker chooses an object ID X to steal. The victim
834           sends an object Y that the attacker already has, and the attacker
835           falsely claims to have X and not Y, so the victim sends Y as a
836           delta against X. The delta reveals regions of X that are similar to
837           Y to the attacker.
838

CONFIGURATION

840       Everything below this line in this section is selectively included from
841       the git-config(1) documentation. The content is the same as what’s
842       found there:
843
844       push.autoSetupRemote
845           If set to "true" assume --set-upstream on default push when no
846           upstream tracking exists for the current branch; this option takes
847           effect with push.default options simple, upstream, and current. It
848           is useful if by default you want new branches to be pushed to the
849           default remote (like the behavior of push.default=current) and you
850           also want the upstream tracking to be set. Workflows most likely to
851           benefit from this option are simple central workflows where all
852           branches are expected to have the same name on the remote.
853
854       push.default
855           Defines the action git push should take if no refspec is given
856           (whether from the command-line, config, or elsewhere). Different
857           values are well-suited for specific workflows; for instance, in a
858           purely central workflow (i.e. the fetch source is equal to the push
859           destination), upstream is probably what you want. Possible values
860           are:
861
862nothing - do not push anything (error out) unless a refspec is
863               given. This is primarily meant for people who want to avoid
864               mistakes by always being explicit.
865
866current - push the current branch to update a branch with the
867               same name on the receiving end. Works in both central and
868               non-central workflows.
869
870upstream - push the current branch back to the branch whose
871               changes are usually integrated into the current branch (which
872               is called @{upstream}). This mode only makes sense if you are
873               pushing to the same repository you would normally pull from
874               (i.e. central workflow).
875
876tracking - This is a deprecated synonym for upstream.
877
878simple - pushes the current branch with the same name on the
879               remote.
880
881               If you are working on a centralized workflow (pushing to the
882               same repository you pull from, which is typically origin), then
883               you need to configure an upstream branch with the same name.
884
885               This mode is the default since Git 2.0, and is the safest
886               option suited for beginners.
887
888matching - push all branches having the same name on both ends.
889               This makes the repository you are pushing to remember the set
890               of branches that will be pushed out (e.g. if you always push
891               maint and master there and no other branches, the repository
892               you push to will have these two branches, and your local maint
893               and master will be pushed there).
894
895               To use this mode effectively, you have to make sure all the
896               branches you would push out are ready to be pushed out before
897               running git push, as the whole point of this mode is to allow
898               you to push all of the branches in one go. If you usually
899               finish work on only one branch and push out the result, while
900               other branches are unfinished, this mode is not for you. Also
901               this mode is not suitable for pushing into a shared central
902               repository, as other people may add new branches there, or
903               update the tip of existing branches outside your control.
904
905               This used to be the default, but not since Git 2.0 (simple is
906               the new default).
907
908       push.followTags
909           If set to true enable --follow-tags option by default. You may
910           override this configuration at time of push by specifying
911           --no-follow-tags.
912
913       push.gpgSign
914           May be set to a boolean value, or the string if-asked. A true value
915           causes all pushes to be GPG signed, as if --signed is passed to
916           git-push(1). The string if-asked causes pushes to be signed if the
917           server supports it, as if --signed=if-asked is passed to git push.
918           A false value may override a value from a lower-priority config
919           file. An explicit command-line flag always overrides this config
920           option.
921
922       push.pushOption
923           When no --push-option=<option> argument is given from the command
924           line, git push behaves as if each <value> of this variable is given
925           as --push-option=<value>.
926
927           This is a multi-valued variable, and an empty value can be used in
928           a higher priority configuration file (e.g.  .git/config in a
929           repository) to clear the values inherited from a lower priority
930           configuration files (e.g.  $HOME/.gitconfig).
931
932               Example:
933
934               /etc/gitconfig
935                 push.pushoption = a
936                 push.pushoption = b
937
938               ~/.gitconfig
939                 push.pushoption = c
940
941               repo/.git/config
942                 push.pushoption =
943                 push.pushoption = b
944
945               This will result in only b (a and c are cleared).
946
947       push.recurseSubmodules
948           May be "check", "on-demand", "only", or "no", with the same
949           behavior as that of "push --recurse-submodules". If not set, no is
950           used by default, unless submodule.recurse is set (in which case a
951           true value means on-demand).
952
953       push.useForceIfIncludes
954           If set to "true", it is equivalent to specifying
955           --force-if-includes as an option to git-push(1) in the command
956           line. Adding --no-force-if-includes at the time of push overrides
957           this configuration setting.
958
959       push.negotiate
960           If set to "true", attempt to reduce the size of the packfile sent
961           by rounds of negotiation in which the client and the server attempt
962           to find commits in common. If "false", Git will rely solely on the
963           server’s ref advertisement to find commits in common.
964
965       push.useBitmaps
966           If set to "false", disable use of bitmaps for "git push" even if
967           pack.useBitmaps is "true", without preventing other git operations
968           from using bitmaps. Default is true.
969

GIT

971       Part of the git(1) suite
972
973
974
975Git 2.39.1                        2023-01-13                       GIT-PUSH(1)
Impressum