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>]]]
14                  [--no-verify] [<repository> [<refspec>...]]
15
16

DESCRIPTION

18       Updates remote refs using local refs, while sending objects necessary
19       to complete the given refs.
20
21       You can make interesting things happen to a repository every time you
22       push into it, by setting up hooks there. See documentation for git-
23       receive-pack(1).
24
25       When the command line does not specify where to push with the
26       <repository> argument, branch.*.remote configuration for the current
27       branch is consulted to determine where to push. If the configuration is
28       missing, it defaults to origin.
29
30       When the command line does not specify what to push with <refspec>...
31       arguments or --all, --mirror, --tags options, the command finds the
32       default <refspec> by consulting remote.*.push configuration, and if it
33       is not found, honors push.default configuration to decide what to push
34       (See git-config(1) for the meaning of push.default).
35
36       When neither the command-line nor the configuration specify what to
37       push, the default behavior is used, which corresponds to the simple
38       value for push.default: the current branch is pushed to the
39       corresponding upstream branch, but as a safety measure, the push is
40       aborted if the upstream branch does not have the same name as the local
41       one.
42

OPTIONS

44       <repository>
45           The "remote" repository that is destination of a push operation.
46           This parameter can be either a URL (see the section GIT URLS below)
47           or the name of a remote (see the section REMOTES 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 the type of <src> being pushed and whether
71           <dst> 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
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 her commit, and blindly pushing with --force will lose
226           her 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       -f, --force
303           Usually, the command refuses to update a remote ref that is not an
304           ancestor of the local ref used to overwrite it. Also, when
305           --force-with-lease option is used, the command refuses to update a
306           remote ref whose current value does not match what is expected.
307
308           This flag disables these checks, and can cause the remote
309           repository to lose commits; use it with care.
310
311           Note that --force applies to all the refs that are pushed, hence
312           using it with push.default set to matching or with multiple push
313           destinations configured with remote.*.push may overwrite refs other
314           than the current branch (including local refs that are strictly
315           behind their remote counterpart). To force a push to only one
316           branch, use a + in front of the refspec to push (e.g git push
317           origin +master to force a push to the master branch). See the
318           <refspec>...  section above for details.
319
320       --repo=<repository>
321           This option is equivalent to the <repository> argument. If both are
322           specified, the command-line argument takes precedence.
323
324       -u, --set-upstream
325           For every branch that is up to date or successfully pushed, add
326           upstream (tracking) reference, used by argument-less git-pull(1)
327           and other commands. For more information, see branch.<name>.merge
328           in git-config(1).
329
330       --[no-]thin
331           These options are passed to git-send-pack(1). A thin transfer
332           significantly reduces the amount of sent data when the sender and
333           receiver share many of the same objects in common. The default is
334           --thin.
335
336       -q, --quiet
337           Suppress all output, including the listing of updated refs, unless
338           an error occurs. Progress is not reported to the standard error
339           stream.
340
341       -v, --verbose
342           Run verbosely.
343
344       --progress
345           Progress status is reported on the standard error stream by default
346           when it is attached to a terminal, unless -q is specified. This
347           flag forces progress status even if the standard error stream is
348           not directed to a terminal.
349
350       --no-recurse-submodules, --recurse-submodules=check|on-demand|only|no
351           May be used to make sure all submodule commits used by the
352           revisions to be pushed are available on a remote-tracking branch.
353           If check is used Git will verify that all submodule commits that
354           changed in the revisions to be pushed are available on at least one
355           remote of the submodule. If any commits are missing the push will
356           be aborted and exit with non-zero status. If on-demand is used all
357           submodules that changed in the revisions to be pushed will be
358           pushed. If on-demand was not able to push all necessary revisions
359           it will also be aborted and exit with non-zero status. If only is
360           used all submodules will be recursively pushed while the
361           superproject is left unpushed. A value of no or using
362           --no-recurse-submodules can be used to override the
363           push.recurseSubmodules configuration variable when no submodule
364           recursion is required.
365
366       --[no-]verify
367           Toggle the pre-push hook (see githooks(5)). The default is
368           --verify, giving the hook a chance to prevent the push. With
369           --no-verify, the hook is bypassed completely.
370
371       -4, --ipv4
372           Use IPv4 addresses only, ignoring IPv6 addresses.
373
374       -6, --ipv6
375           Use IPv6 addresses only, ignoring IPv4 addresses.
376

GIT URLS

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

REMOTES

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

OUTPUT

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

NOTE ABOUT FAST-FORWARDS

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

EXAMPLES

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

SECURITY

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

GIT

824       Part of the git(1) suite
825
826
827
828Git 2.21.0                        02/24/2019                       GIT-PUSH(1)
Impressum