Documentation/git-push: document that 'simple' is the default
[git.git] / Documentation / git-push.txt
blobd8c30a9c810a1d3583cf6eb6885388d00687adc6
1 git-push(1)
2 ===========
4 NAME
5 ----
6 git-push - Update remote refs along with associated objects
9 SYNOPSIS
10 --------
11 [verse]
12 'git push' [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
13            [--repo=<repository>] [-f | --force] [--prune] [-v | --verbose]
14            [-u | --set-upstream] [--signed]
15            [--force-with-lease[=<refname>[:<expect>]]]
16            [--no-verify] [<repository> [<refspec>...]]
18 DESCRIPTION
19 -----------
21 Updates remote refs using local refs, while sending objects
22 necessary to complete the given refs.
24 You can make interesting things happen to a repository
25 every time you push into it, by setting up 'hooks' there.  See
26 documentation for linkgit:git-receive-pack[1].
28 When the command line does not specify where to push with the
29 `<repository>` argument, `branch.*.remote` configuration for the
30 current branch is consulted to determine where to push.  If the
31 configuration is missing, it defaults to 'origin'.
33 When the command line does not specify what to push with `<refspec>...`
34 arguments or `--all`, `--mirror`, `--tags` options, the command finds
35 the default `<refspec>` by consulting `remote.*.push` configuration,
36 and if it is not found, honors `push.default` configuration to decide
37 what to push (See linkgit:git-config[1] for the meaning of `push.default`).
39 When neither the command-line nor the configuration specify what to
40 push, the default behavior is used, which corresponds to the `simple`
41 value for `push.default`: the current branch is pushed to the
42 corresponding upstream branch, but as a safety measure, the push is
43 aborted if the upstream branch does not have the same name as the
44 local one.
47 OPTIONS[[OPTIONS]]
48 ------------------
49 <repository>::
50         The "remote" repository that is destination of a push
51         operation.  This parameter can be either a URL
52         (see the section <<URLS,GIT URLS>> below) or the name
53         of a remote (see the section <<REMOTES,REMOTES>> below).
55 <refspec>...::
56         Specify what destination ref to update with what source object.
57         The format of a <refspec> parameter is an optional plus
58         `+`, followed by the source object <src>, followed
59         by a colon `:`, followed by the destination ref <dst>.
61 The <src> is often the name of the branch you would want to push, but
62 it can be any arbitrary "SHA-1 expression", such as `master~4` or
63 `HEAD` (see linkgit:gitrevisions[7]).
65 The <dst> tells which ref on the remote side is updated with this
66 push. Arbitrary expressions cannot be used here, an actual ref must
67 be named.
68 If `git push [<repository>]` without any `<refspec>` argument is set to
69 update some ref at the destination with `<src>` with
70 `remote.<repository>.push` configuration variable, `:<dst>` part can
71 be omitted---such a push will update a ref that `<src>` normally updates
72 without any `<refspec>` on the command line.  Otherwise, missing
73 `:<dst>` means to update the same ref as the `<src>`.
75 The object referenced by <src> is used to update the <dst> reference
76 on the remote side.  By default this is only allowed if <dst> is not
77 a tag (annotated or lightweight), and then only if it can fast-forward
78 <dst>.  By having the optional leading `+`, you can tell Git to update
79 the <dst> ref even if it is not allowed by default (e.g., it is not a
80 fast-forward.)  This does *not* attempt to merge <src> into <dst>.  See
81 EXAMPLES below for details.
83 `tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`.
85 Pushing an empty <src> allows you to delete the <dst> ref from
86 the remote repository.
88 The special refspec `:` (or `+:` to allow non-fast-forward updates)
89 directs Git to push "matching" branches: for every branch that exists on
90 the local side, the remote side is updated if a branch of the same name
91 already exists on the remote side.
93 --all::
94         Push all branches (i.e. refs under `refs/heads/`); cannot be
95         used with other <refspec>.
97 --prune::
98         Remove remote branches that don't have a local counterpart. For example
99         a remote branch `tmp` will be removed if a local branch with the same
100         name doesn't exist any more. This also respects refspecs, e.g.
101         `git push --prune remote refs/heads/*:refs/tmp/*` would
102         make sure that remote `refs/tmp/foo` will be removed if `refs/heads/foo`
103         doesn't exist.
105 --mirror::
106         Instead of naming each ref to push, specifies that all
107         refs under `refs/` (which includes but is not
108         limited to `refs/heads/`, `refs/remotes/`, and `refs/tags/`)
109         be mirrored to the remote repository.  Newly created local
110         refs will be pushed to the remote end, locally updated refs
111         will be force updated on the remote end, and deleted refs
112         will be removed from the remote end.  This is the default
113         if the configuration option `remote.<remote>.mirror` is
114         set.
116 -n::
117 --dry-run::
118         Do everything except actually send the updates.
120 --porcelain::
121         Produce machine-readable output.  The output status line for each ref
122         will be tab-separated and sent to stdout instead of stderr.  The full
123         symbolic names of the refs will be given.
125 --delete::
126         All listed refs are deleted from the remote repository. This is
127         the same as prefixing all refs with a colon.
129 --tags::
130         All refs under `refs/tags` are pushed, in
131         addition to refspecs explicitly listed on the command
132         line.
134 --follow-tags::
135         Push all the refs that would be pushed without this option,
136         and also push annotated tags in `refs/tags` that are missing
137         from the remote but are pointing at commit-ish that are
138         reachable from the refs being pushed.  This can also be specified
139         with configuration variable 'push.followTags'.  For more
140         information, see 'push.followTags' in linkgit:git-config[1].
143 --signed::
144         GPG-sign the push request to update refs on the receiving
145         side, to allow it to be checked by the hooks and/or be
146         logged.  See linkgit:git-receive-pack[1] for the details
147         on the receiving end.
149 --[no-]atomic::
150         Use an atomic transaction on the remote side if available.
151         Either all refs are updated, or on error, no refs are updated.
152         If the server does not support atomic pushes the push will fail.
154 --receive-pack=<git-receive-pack>::
155 --exec=<git-receive-pack>::
156         Path to the 'git-receive-pack' program on the remote
157         end.  Sometimes useful when pushing to a remote
158         repository over ssh, and you do not have the program in
159         a directory on the default $PATH.
161 --[no-]force-with-lease::
162 --force-with-lease=<refname>::
163 --force-with-lease=<refname>:<expect>::
164         Usually, "git push" refuses to update a remote ref that is
165         not an ancestor of the local ref used to overwrite it.
167 This option overrides this restriction if the current value of the
168 remote ref is the expected value.  "git push" fails otherwise.
170 Imagine that you have to rebase what you have already published.
171 You will have to bypass the "must fast-forward" rule in order to
172 replace the history you originally published with the rebased history.
173 If somebody else built on top of your original history while you are
174 rebasing, the tip of the branch at the remote may advance with her
175 commit, and blindly pushing with `--force` will lose her work.
177 This option allows you to say that you expect the history you are
178 updating is what you rebased and want to replace. If the remote ref
179 still points at the commit you specified, you can be sure that no
180 other people did anything to the ref. It is like taking a "lease" on
181 the ref without explicitly locking it, and the remote ref is updated
182 only if the "lease" is still valid.
184 `--force-with-lease` alone, without specifying the details, will protect
185 all remote refs that are going to be updated by requiring their
186 current value to be the same as the remote-tracking branch we have
187 for them.
189 `--force-with-lease=<refname>`, without specifying the expected value, will
190 protect the named ref (alone), if it is going to be updated, by
191 requiring its current value to be the same as the remote-tracking
192 branch we have for it.
194 `--force-with-lease=<refname>:<expect>` will protect the named ref (alone),
195 if it is going to be updated, by requiring its current value to be
196 the same as the specified value <expect> (which is allowed to be
197 different from the remote-tracking branch we have for the refname,
198 or we do not even have to have such a remote-tracking branch when
199 this form is used).
201 Note that all forms other than `--force-with-lease=<refname>:<expect>`
202 that specifies the expected current value of the ref explicitly are
203 still experimental and their semantics may change as we gain experience
204 with this feature.
206 "--no-force-with-lease" will cancel all the previous --force-with-lease on the
207 command line.
209 -f::
210 --force::
211         Usually, the command refuses to update a remote ref that is
212         not an ancestor of the local ref used to overwrite it.
213         Also, when `--force-with-lease` option is used, the command refuses
214         to update a remote ref whose current value does not match
215         what is expected.
217 This flag disables these checks, and can cause the remote repository
218 to lose commits; use it with care.
220 Note that `--force` applies to all the refs that are pushed, hence
221 using it with `push.default` set to `matching` or with multiple push
222 destinations configured with `remote.*.push` may overwrite refs
223 other than the current branch (including local refs that are
224 strictly behind their remote counterpart).  To force a push to only
225 one branch, use a `+` in front of the refspec to push (e.g `git push
226 origin +master` to force a push to the `master` branch). See the
227 `<refspec>...` section above for details.
229 --repo=<repository>::
230         This option is equivalent to the <repository> argument. If both
231         are specified, the command-line argument takes precedence.
233 -u::
234 --set-upstream::
235         For every branch that is up to date or successfully pushed, add
236         upstream (tracking) reference, used by argument-less
237         linkgit:git-pull[1] and other commands. For more information,
238         see 'branch.<name>.merge' in linkgit:git-config[1].
240 --[no-]thin::
241         These options are passed to linkgit:git-send-pack[1]. A thin transfer
242         significantly reduces the amount of sent data when the sender and
243         receiver share many of the same objects in common. The default is
244         \--thin.
246 -q::
247 --quiet::
248         Suppress all output, including the listing of updated refs,
249         unless an error occurs. Progress is not reported to the standard
250         error stream.
252 -v::
253 --verbose::
254         Run verbosely.
256 --progress::
257         Progress status is reported on the standard error stream
258         by default when it is attached to a terminal, unless -q
259         is specified. This flag forces progress status even if the
260         standard error stream is not directed to a terminal.
262 --recurse-submodules=check|on-demand::
263         Make sure all submodule commits used by the revisions to be
264         pushed are available on a remote-tracking branch. If 'check' is
265         used Git will verify that all submodule commits that changed in
266         the revisions to be pushed are available on at least one remote
267         of the submodule. If any commits are missing the push will be
268         aborted and exit with non-zero status. If 'on-demand' is used
269         all submodules that changed in the revisions to be pushed will
270         be pushed. If on-demand was not able to push all necessary
271         revisions it will also be aborted and exit with non-zero status.
273 --[no-]verify::
274         Toggle the pre-push hook (see linkgit:githooks[5]).  The
275         default is --verify, giving the hook a chance to prevent the
276         push.  With --no-verify, the hook is bypassed completely.
279 include::urls-remotes.txt[]
281 OUTPUT
282 ------
284 The output of "git push" depends on the transport method used; this
285 section describes the output when pushing over the Git protocol (either
286 locally or via ssh).
288 The status of the push is output in tabular form, with each line
289 representing the status of a single ref. Each line is of the form:
291 -------------------------------
292  <flag> <summary> <from> -> <to> (<reason>)
293 -------------------------------
295 If --porcelain is used, then each line of the output is of the form:
297 -------------------------------
298  <flag> \t <from>:<to> \t <summary> (<reason>)
299 -------------------------------
301 The status of up-to-date refs is shown only if --porcelain or --verbose
302 option is used.
304 flag::
305         A single character indicating the status of the ref:
306 (space);; for a successfully pushed fast-forward;
307 `+`;; for a successful forced update;
308 `-`;; for a successfully deleted ref;
309 `*`;; for a successfully pushed new ref;
310 `!`;; for a ref that was rejected or failed to push; and
311 `=`;; for a ref that was up to date and did not need pushing.
313 summary::
314         For a successfully pushed ref, the summary shows the old and new
315         values of the ref in a form suitable for using as an argument to
316         `git log` (this is `<old>..<new>` in most cases, and
317         `<old>...<new>` for forced non-fast-forward updates).
319 For a failed update, more details are given:
322 rejected::
323         Git did not try to send the ref at all, typically because it
324         is not a fast-forward and you did not force the update.
326 remote rejected::
327         The remote end refused the update.  Usually caused by a hook
328         on the remote side, or because the remote repository has one
329         of the following safety options in effect:
330         `receive.denyCurrentBranch` (for pushes to the checked out
331         branch), `receive.denyNonFastForwards` (for forced
332         non-fast-forward updates), `receive.denyDeletes` or
333         `receive.denyDeleteCurrent`.  See linkgit:git-config[1].
335 remote failure::
336         The remote end did not report the successful update of the ref,
337         perhaps because of a temporary error on the remote side, a
338         break in the network connection, or other transient error.
341 from::
342         The name of the local ref being pushed, minus its
343         `refs/<type>/` prefix. In the case of deletion, the
344         name of the local ref is omitted.
346 to::
347         The name of the remote ref being updated, minus its
348         `refs/<type>/` prefix.
350 reason::
351         A human-readable explanation. In the case of successfully pushed
352         refs, no explanation is needed. For a failed ref, the reason for
353         failure is described.
355 Note about fast-forwards
356 ------------------------
358 When an update changes a branch (or more in general, a ref) that used to
359 point at commit A to point at another commit B, it is called a
360 fast-forward update if and only if B is a descendant of A.
362 In a fast-forward update from A to B, the set of commits that the original
363 commit A built on top of is a subset of the commits the new commit B
364 builds on top of.  Hence, it does not lose any history.
366 In contrast, a non-fast-forward update will lose history.  For example,
367 suppose you and somebody else started at the same commit X, and you built
368 a history leading to commit B while the other person built a history
369 leading to commit A.  The history looks like this:
371 ----------------
373       B
374      /
375  ---X---A
377 ----------------
379 Further suppose that the other person already pushed changes leading to A
380 back to the original repository from which you two obtained the original
381 commit X.
383 The push done by the other person updated the branch that used to point at
384 commit X to point at commit A.  It is a fast-forward.
386 But if you try to push, you will attempt to update the branch (that
387 now points at A) with commit B.  This does _not_ fast-forward.  If you did
388 so, the changes introduced by commit A will be lost, because everybody
389 will now start building on top of B.
391 The command by default does not allow an update that is not a fast-forward
392 to prevent such loss of history.
394 If you do not want to lose your work (history from X to B) or the work by
395 the other person (history from X to A), you would need to first fetch the
396 history from the repository, create a history that contains changes done
397 by both parties, and push the result back.
399 You can perform "git pull", resolve potential conflicts, and "git push"
400 the result.  A "git pull" will create a merge commit C between commits A
401 and B.
403 ----------------
405       B---C
406      /   /
407  ---X---A
409 ----------------
411 Updating A with the resulting merge commit will fast-forward and your
412 push will be accepted.
414 Alternatively, you can rebase your change between X and B on top of A,
415 with "git pull --rebase", and push the result back.  The rebase will
416 create a new commit D that builds the change between X and B on top of
419 ----------------
421       B   D
422      /   /
423  ---X---A
425 ----------------
427 Again, updating A with this commit will fast-forward and your push will be
428 accepted.
430 There is another common situation where you may encounter non-fast-forward
431 rejection when you try to push, and it is possible even when you are
432 pushing into a repository nobody else pushes into. After you push commit
433 A yourself (in the first picture in this section), replace it with "git
434 commit --amend" to produce commit B, and you try to push it out, because
435 forgot that you have pushed A out already. In such a case, and only if
436 you are certain that nobody in the meantime fetched your earlier commit A
437 (and started building on top of it), you can run "git push --force" to
438 overwrite it. In other words, "git push --force" is a method reserved for
439 a case where you do mean to lose history.
442 Examples
443 --------
445 `git push`::
446         Works like `git push <remote>`, where <remote> is the
447         current branch's remote (or `origin`, if no remote is
448         configured for the current branch).
450 `git push origin`::
451         Without additional configuration, pushes the current branch to
452         the configured upstream (`remote.origin.merge` configuration
453         variable) if it has the same name as the current branch, and
454         errors out without pushing otherwise.
456 The default behavior of this command when no <refspec> is given can be
457 configured by setting the `push` option of the remote, or the `push.default`
458 configuration variable.
460 For example, to default to pushing only the current branch to `origin`
461 use `git config remote.origin.push HEAD`.  Any valid <refspec> (like
462 the ones in the examples below) can be configured as the default for
463 `git push origin`.
465 `git push origin :`::
466         Push "matching" branches to `origin`. See
467         <refspec> in the <<OPTIONS,OPTIONS>> section above for a
468         description of "matching" branches.
470 `git push origin master`::
471         Find a ref that matches `master` in the source repository
472         (most likely, it would find `refs/heads/master`), and update
473         the same ref (e.g. `refs/heads/master`) in `origin` repository
474         with it.  If `master` did not exist remotely, it would be
475         created.
477 `git push origin HEAD`::
478         A handy way to push the current branch to the same name on the
479         remote.
481 `git push mothership master:satellite/master dev:satellite/dev`::
482         Use the source ref that matches `master` (e.g. `refs/heads/master`)
483         to update the ref that matches `satellite/master` (most probably
484         `refs/remotes/satellite/master`) in the `mothership` repository;
485         do the same for `dev` and `satellite/dev`.
487 This is to emulate `git fetch` run on the `mothership` using `git
488 push` that is run in the opposite direction in order to integrate
489 the work done on `satellite`, and is often necessary when you can
490 only make connection in one way (i.e. satellite can ssh into
491 mothership but mothership cannot initiate connection to satellite
492 because the latter is behind a firewall or does not run sshd).
494 After running this `git push` on the `satellite` machine, you would
495 ssh into the `mothership` and run `git merge` there to complete the
496 emulation of `git pull` that were run on `mothership` to pull changes
497 made on `satellite`.
499 `git push origin HEAD:master`::
500         Push the current branch to the remote ref matching `master` in the
501         `origin` repository. This form is convenient to push the current
502         branch without thinking about its local name.
504 `git push origin master:refs/heads/experimental`::
505         Create the branch `experimental` in the `origin` repository
506         by copying the current `master` branch.  This form is only
507         needed to create a new branch or tag in the remote repository when
508         the local name and the remote name are different; otherwise,
509         the ref name on its own will work.
511 `git push origin :experimental`::
512         Find a ref that matches `experimental` in the `origin` repository
513         (e.g. `refs/heads/experimental`), and delete it.
515 `git push origin +dev:master`::
516         Update the origin repository's master branch with the dev branch,
517         allowing non-fast-forward updates.  *This can leave unreferenced
518         commits dangling in the origin repository.*  Consider the
519         following situation, where a fast-forward is not possible:
521 ----
522             o---o---o---A---B  origin/master
523                      \
524                       X---Y---Z  dev
525 ----
527 The above command would change the origin repository to
529 ----
530                       A---B  (unnamed branch)
531                      /
532             o---o---o---X---Y---Z  master
533 ----
535 Commits A and B would no longer belong to a branch with a symbolic name,
536 and so would be unreachable.  As such, these commits would be removed by
537 a `git gc` command on the origin repository.
541 Part of the linkgit:git[1] suite