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 her commit, and blindly pushing with --force will lose
225           her 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 recursively pushed while the
384           superproject is left unpushed. A value of no or using
385           --no-recurse-submodules can be used to override the
386           push.recurseSubmodules configuration variable when no submodule
387           recursion is required.
388
389       --[no-]verify
390           Toggle the pre-push hook (see githooks(5)). The default is
391           --verify, giving the hook a chance to prevent the push. With
392           --no-verify, the hook is bypassed completely.
393
394       -4, --ipv4
395           Use IPv4 addresses only, ignoring IPv6 addresses.
396
397       -6, --ipv6
398           Use IPv6 addresses only, ignoring IPv4 addresses.
399

GIT URLS

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

REMOTES

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

OUTPUT

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

NOTE ABOUT FAST-FORWARDS

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

EXAMPLES

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

SECURITY

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

GIT

836       Part of the git(1) suite
837
838
839
840Git 2.31.1                        2021-03-26                       GIT-PUSH(1)
Impressum