git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: What's cooking in git.git (topics)

From
JFJ. Bruce Fields <bfields@fieldses.org>
Date
Nov 25, 2007, 21:51 UTC
Message-ID
<20071125215128.GC23820@fieldses.org>
In-Reply-To
<7vtznbqx2w.fsf@gitster.siamese.dyndns.org>
On Sat, Nov 24, 2007 at 11:09:59AM -0800, Junio C Hamano wrote:
Show 47 quoted lines
> Nicolas Pitre <nico@cam.org> writes:
> > I think that would be better to append a single line at the end of the 
> > display with a clue about what "non fast forward" means.
> 
> I'd agree, but having said all the above, I am not entirely
> happy not mentioning "what next" at all.
> 
> There are two equally valid "what next" after your push is
> rejected due to non-fast-forwardness.
> 
>  (1) You know what you are doing.
> 
>    - You are pushing into a "back-up" repository, not for a
>      public consumption.
> 
>    - You are pushing a branch that are advertised to rebase and
>      rewind into your own publishing repository, and other
>      people interacting with the branch know about this.
> 
>    - You pushed a wrong head there very recently and are fairly
>      confident that nobody has seen that mistake, and pushing
>      the correct one to fix the mistake.
> 
>      In these cases, forcing the push is the right solution
>      (except that the third one is dubious, because it depends
>      heavily on the "fairly confident" part).
> 
>  (2) You were building on a stale head, and were indeed about to
>      lose others' changes with a non-fast-forward push.
> 
>      The right solution is to rebuild what you push so that you
>      will not lose others' changes.  Rebuilding can take two
>      different forms:
> 
>    - You may want to git-fetch and rebase your work on top of
>      others'.
> 
>    - You may want to git-pull, which will merge your work with
>      what others did.
> 
> But of couse the above is way too long as the help text.
> 
> Does the user-manual talk about this?  It has a really good
> description of how to notice when a merge is not resolved
> automatically and what to do next ("Resolving a merge" section).
> Perhaps we can enhance "Pushing changes to a public repository"
> section to include "what if the push is refused" information.
There's a very brief mention of this:
	"As with git-fetch, git-push will complain if this does not
	result in a <<fast-forwards,fast forward>>.  Normally this is a
	sign of something wrong.  However, if you are sure you know what
	you're doing, you may force git-push to perform the update
	anyway by preceding the branch name by a plus sign:

But it'd probably be better to have a separate section. That makes it possible to say a little more, and also gets a section called "what to do when a push fails" into the table of contents.

(Though that's a little vague--push can also fail just because you mispell the url or something. A more precise reference to the particular error might be better, but we'll have to agree on the error message first....)

Anyway, here's a first draft.
--b.
diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt
index 8355cce..7544715 100644
--- a/Documentation/user-manual.txt
+++ b/Documentation/user-manual.txt
@@ -1929,15 +1929,9 @@ or just
 $ git push ssh://yourserver.com/~you/proj.git master
 -------------------------------------------------
 
-As with git-fetch, git-push will complain if this does not result in
-a <<fast-forwards,fast forward>>.  Normally this is a sign of
-something wrong.  However, if you are sure you know what you're
-doing, you may force git-push to perform the update anyway by
-proceeding the branch name by a plus sign:
-
--------------------------------------------------
-$ git push ssh://yourserver.com/~you/proj.git +master
--------------------------------------------------
+As with git-fetch, git-push will complain if this does not result in a
+<<fast-forwards,fast forward>>; see the following section for details on
+handling this case.
 
 Note that the target of a "push" is normally a
 <<def_bare_repository,bare>> repository.  You can also push to a
@@ -1965,6 +1959,55 @@ See the explanations of the remote.<name>.url, branch.<name>.remote,
 and remote.<name>.push options in gitlink:git-config[1] for
 details.
 
+[[forcing-push]]
+What to do when a push fails
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If the push does not result in a <<fast-forwards,fast forward>> of the
+remote branch, then it will fail with an error like:
+
+-------------------------------------------------
+error: remote 'refs/heads/master' is not an ancestor of
+ local  'refs/heads/master'.
+ Maybe you are not up-to-date and need to pull first?
+error: failed to push to 'ssh://yourserver.com/~you/proj.git'
+-------------------------------------------------
+
+The most likely reason for this is that you have replaced some of the
+history that you already pushed, so that your "master" is no longer a
+descendant of upstream's "master",  This could happen, for example, if
+you:
+
+	- use `git reset --hard` to remove already-published commits, or
+	- use `git commit --amend` to replace already-published commits
+	  (as in <<fixing-a-mistake-by-editing-history>>), or
+	- use `git rebase` to rebase any already-published commits (as
+	  in <<using-git-rebase>>).
+
+If you are sure you want to replace the branch in the public repository
+by your branch, you may force git-push to perform the update anyway by
+preceding the branch name with a plus sign:
+
+-------------------------------------------------
+$ git push ssh://yourserver.com/~you/proj.git +master
+-------------------------------------------------
+
+Normally whenever a branch head in a public repository is modified, it
+is modified to point to a descendent of the commit that it pointed to
+before.  By forcing a push in this situation, you break that convention.
+(See <<problems-with-rewriting-history>>).
+
+Nevertheless, this is a common practice for people that need a simple
+way to publish a work-in-progress patch series, and it is an acceptable
+compromise as long as you warn other developers that this is how you
+intend to manage the branch.
+
+It's also possible for a push to fail in this way when other people have
+the right to push to the same repository.  In that case, the correct
+solution is to update your work by either a pull or a fetch followed by
+a rebase; see the <<setting-up-a-shared-repository,next section>> for
+more.
+
 [[setting-up-a-shared-repository]]
 Setting up a shared repository
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Previous: Junio C HamanoNext: Junio C Hamano
Message 102 of 168 in “What's cooking in git/spearce.git (topics)”
  1. Shawn O. PearceOct 22, 2007
  2. Jeff KingOct 22, 2007
  3. Jeff KingOct 22, 2007
  4. Linus TorvaldsOct 23, 2007
  5. Jeff KingOct 23, 2007
  6. Pierre HabouzitOct 22, 2007
  7. Steffen ProhaskaOct 22, 2007
  8. Junio C HamanoOct 23, 2007
  9. Shawn O. PearceOct 23, 2007
  10. What's cooking in git.git (topics)Junio C Hamano, Oct 24, 2007
  11. David SymondsOct 24, 2007
  12. Scott ParishOct 24, 2007
  13. Andreas EricssonOct 24, 2007
  14. Scott ParishOct 25, 2007
  15. What's cooking in git.git (topics)Junio C Hamano, Nov 1, 2007
  16. Jakub NarebskiNov 1, 2007
  17. Junio C HamanoNov 1, 2007
  18. Linus TorvaldsNov 1, 2007
  19. Geert BoschNov 1, 2007
  20. Junio C HamanoNov 1, 2007
  21. Mike HommeyNov 1, 2007
  22. Junio C HamanoNov 1, 2007
  23. Junio C HamanoNov 2, 2007
  24. Pierre HabouzitNov 1, 2007
  25. Geert BoschNov 1, 2007
  26. Jonas FonsecaNov 2, 2007
  27. Theodore TsoNov 1, 2007
  28. Melchior FRANZNov 1, 2007
  29. Johan HerlandNov 1, 2007
  30. Junio C HamanoNov 1, 2007
  31. Linus TorvaldsNov 1, 2007
  32. Bill LearNov 1, 2007
  33. Junio C HamanoNov 1, 2007
  34. Petr BaudisNov 2, 2007
  35. Pierre HabouzitNov 1, 2007
  36. Andreas EricssonNov 2, 2007
  37. Pierre HabouzitNov 1, 2007
  38. Jakub NarebskiNov 2, 2007
  39. Petr BaudisNov 2, 2007
  40. Jakub NarebskiNov 2, 2007
  41. Jakub NarebskiNov 2, 2007
  42. Pierre HabouzitNov 2, 2007
  43. Miles BaderNov 2, 2007
  44. Miles BaderNov 2, 2007
  45. Andreas EricssonNov 2, 2007
  46. Johannes SchindelinNov 2, 2007
  47. Brian DowningNov 1, 2007
  48. Pierre HabouzitNov 1, 2007
  49. Wincent ColaiutaNov 2, 2007
  50. What's cooking in git.git (topics)Junio C Hamano, Nov 4, 2007
  51. Jakub NarebskiNov 4, 2007
  52. Pierre HabouzitNov 4, 2007
  53. What's cooking in git.git (topics)Junio C Hamano, Nov 8, 2007
  54. Steffen ProhaskaNov 8, 2007
  55. What's cooking in git.git (topics)Junio C Hamano, Nov 12, 2007
  56. Johannes SchindelinNov 12, 2007
  57. Pierre HabouzitNov 12, 2007
  58. Johannes SchindelinNov 12, 2007
  59. rebase: brown paper bag fix after the detached HEAD patchJohannes Schindelin, Nov 12, 2007
  60. Pierre HabouzitNov 12, 2007
  61. Steffen ProhaskaNov 12, 2007
  62. Johannes SchindelinNov 12, 2007
  63. 1/2 push: Add '--matching' option and print warning if it should be usedSteffen Prohaska, Nov 18, 2007
  64. 2/2 push: Add '--current', which pushes only the current branchSteffen Prohaska, Nov 18, 2007
  65. Junio C HamanoNov 19, 2007
  66. Steffen ProhaskaNov 19, 2007
  67. Junio C HamanoNov 19, 2007
  68. Junio C HamanoNov 19, 2007
  69. Andreas EricssonNov 19, 2007
  70. Steffen ProhaskaNov 19, 2007
  71. Junio C HamanoNov 19, 2007
  72. Steffen ProhaskaNov 19, 2007
  73. push: Add "--current", which pushes only the current branchSteffen Prohaska, Nov 19, 2007
  74. Jakub NarebskiNov 19, 2007
  75. Junio C HamanoNov 19, 2007
  76. Jakub NarebskiNov 19, 2007
  77. Junio C HamanoNov 19, 2007
  78. Jakub NarebskiNov 19, 2007
  79. Andreas EricssonNov 19, 2007
  80. git-commit: Add tests for invalid usage of -a/--interactive with pathsBjörn Steinbrink, Nov 12, 2007
  81. What's cooking in git.git (topics)Junio C Hamano, Nov 15, 2007
  82. Johannes SchindelinNov 15, 2007
  83. t7501-commit: Add test for git commit <file> with dirty index.Kristian Høgsberg, Nov 15, 2007
  84. Johannes SchindelinNov 15, 2007
  85. builtin-commit: fix "git add x y && git commit y" committing x, tooJohannes Schindelin, Nov 15, 2007
  86. Johannes SchindelinNov 15, 2007
  87. Kristian HøgsbergNov 15, 2007
  88. Johannes SchindelinNov 16, 2007
  89. Junio C HamanoNov 17, 2007
  90. Junio C HamanoNov 18, 2007
  91. Jeff KingNov 17, 2007
  92. What's cooking in git.git (topics)Junio C Hamano, Nov 17, 2007
  93. Alex RiesenNov 17, 2007
  94. Junio C HamanoNov 18, 2007
  95. What's cooking in git.git (topics)Junio C Hamano, Nov 21, 2007
  96. What's cooking in git.git (topics)Junio C Hamano, Nov 23, 2007
  97. Jeff KingNov 23, 2007
  98. Johannes SchindelinNov 23, 2007
  99. Jeff KingNov 24, 2007
  100. Nicolas PitreNov 24, 2007
  101. Junio C HamanoNov 24, 2007
  102. J. Bruce FieldsNov 25, 2007
  103. Junio C HamanoNov 25, 2007
  104. J. Bruce FieldsNov 25, 2007
  105. Nicolas PitreNov 26, 2007
  106. J. Bruce FieldsNov 26, 2007
  107. Nicolas PitreNov 26, 2007
  108. J. Bruce FieldsNov 26, 2007
  109. Jakub NarebskiNov 26, 2007
  110. Andreas EricssonNov 26, 2007
  111. Nicolas PitreNov 26, 2007
  112. David KastrupNov 26, 2007
  113. Nicolas PitreNov 26, 2007
  114. Junio C HamanoNov 26, 2007
  115. David KastrupNov 26, 2007
  116. Nicolas PitreNov 26, 2007
  117. David KastrupNov 26, 2007
  118. Nicolas PitreNov 26, 2007
  119. David KastrupNov 26, 2007
  120. Nicolas PitreNov 26, 2007
  121. David KastrupNov 26, 2007
  122. Nicolas PitreNov 27, 2007
  123. Miles BaderDec 5, 2007
  124. Jakub NarebskiNov 26, 2007
  125. Johannes SchindelinNov 26, 2007
  126. Nicolas PitreNov 26, 2007
  127. Jan HudecNov 26, 2007
  128. What's cooking in git.git (topics)Junio C Hamano, Nov 25, 2007
  129. Jakub NarebskiNov 25, 2007
  130. J. Bruce FieldsNov 25, 2007
  131. What's cooking in git.git (topics)Junio C Hamano, Dec 1, 2007
  132. Eric WongDec 1, 2007
  133. Add 'git fast-export', the sister of 'git fast-import'Johannes Schindelin, Dec 2, 2007
  134. Johannes SchindelinDec 2, 2007
  135. What's cooking in git.git (topics)Junio C Hamano, Dec 4, 2007
  136. Johannes SixtDec 4, 2007
  137. msysGit on FAT32 (was: What's cooking in git.git (topics))Jakub Narebski, Dec 4, 2007
  138. Johannes SchindelinDec 4, 2007
  139. Johannes SixtDec 4, 2007
  140. Johannes SchindelinDec 4, 2007
  141. Steffen ProhaskaDec 4, 2007
  142. What's cooking in git.git (topics)Junio C Hamano, Dec 5, 2007
  143. Jakub NarebskiDec 5, 2007
  144. Jakub NarebskiDec 5, 2007
  145. Jeff KingDec 6, 2007
  146. Soft aliases: add "less" and minimal documentationJohannes Schindelin, Dec 5, 2007
  147. Junio C HamanoDec 5, 2007
  148. Jeff KingDec 6, 2007
  149. Jeff KingDec 6, 2007
  150. What's cooking in git.git (topics)Junio C Hamano, Dec 7, 2007
  151. Jakub NarebskiDec 7, 2007
  152. Junio C HamanoDec 7, 2007
  153. Miklos VajnaDec 7, 2007
  154. What's cooking in git.git (topics)Junio C Hamano, Dec 9, 2007
  155. What's cooking in git.git (topics)Junio C Hamano, Dec 13, 2007
  156. Nicolas PitreDec 13, 2007
  157. 1/2 xdl_diff: identify call sites.Junio C Hamano, Dec 13, 2007
  158. Junio C HamanoDec 14, 2007
  159. 2/2 xdi_diff: trim common trailing linesJunio C Hamano, Dec 13, 2007
  160. Peter BaumannDec 14, 2007
  161. Junio C HamanoDec 14, 2007
  162. What's cooking in git.git (topics)Junio C Hamano, Dec 17, 2007
  163. What's cooking in git.git (topics)Junio C Hamano, Dec 23, 2007
  164. checkout --push/--pop idea (Re: What's cooking in git.git (topics))Jan Hudec, Dec 31, 2007
  165. What's cooking in git.git (topics)Junio C Hamano, Jan 5, 2008
  166. Johannes SchindelinJan 5, 2008
  167. What will be cooking in git.git post 1.5.4 (topics)Junio C Hamano, Jan 22, 2008
  168. Brian DowningDec 4, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.