@@ -376,30 +376,43 @@ to replace your already published commits with the new ones.
376376Pushing, with force
377377-------------------
378378
379+
379380If you have in some way re-written already pushed history (e.g. via
380- :ref: `rewriting-commit-history ` or :ref: `rebase-on-main `), then when you try to
381- push the new commits to GitHub it will fail with an error that looks like ::
381+ :ref: `rewriting-commit-history ` or :ref: `rebase-on-main `) leaving you with
382+ a git history that looks something like
383+
384+ .. code-block :: none
385+
386+ A'--E cool-feature
387+ /
388+ D---A---B---C origin/cool-feature
389+
390+ where you have pushed the commits ``A,B,C `` to your fork on GitHub (under the
391+ remote name *origin *) but now have the commits ``A' `` and ``E `` on your local
392+ branch *cool-feature *. If you try to push the new commits to GitHub it will
393+ fail with an error that looks like ::
382394
383395 $ git push
384- Pushing to github.com:YOURFORK /matplotlib.git
385- To github.com:YOURFORK /matplotlib.git
396+ Pushing to github.com:origin /matplotlib.git
397+ To github.com:origin /matplotlib.git
386398 ! [rejected] cool_feature -> cool_feature (non-fast-forward)
387- error: failed to push some refs to 'github.com:tacaswell /matplotlib.git'
399+ error: failed to push some refs to 'github.com:origin /matplotlib.git'
388400 hint: Updates were rejected because the tip of your current branch is behind
389401 hint: its remote counterpart. Integrate the remote changes (e.g.
390402 hint: 'git pull ...') before pushing again.
391403 hint: See the 'Note about fast-forwards' in 'git push --help' for details.
392404
393- What is going on is that by default ``git push `` tries to protect you from
394- accidentally discarding commits on the remote by rejecting the
395- push. When this happens, GitHub adds the helpful suggestion to pull the remote
396- changes and then try pushing again. In some cases, such as if you and a
397- colleague are both committing and pushing to the same branch, this is the
398- correct course of action (or rebase your local branch but it is a matter of
399- taste).
400-
401- However, in the case of having intentionally re-written history we *want * to discard the commits and
402- replace them with the new-and-improved versions from our local branch. In these cases, what we want to do is ::
405+ If this push had succeed then the commits ``A ``, ``B ``, and ``C `` would no
406+ longer be referenced by any branch and be discarded. By default ``git push ``
407+ helpfully tries to protect you from accidentally discarding commits by
408+ rejecting the push to the remote. When this happens, GitHub also adds the
409+ helpful suggestion to pull the remote changes and then try pushing again. In
410+ some cases, such as if you and a colleague are both committing and pushing to
411+ the same branch, this is a correct course of action.
412+
413+ However, in the case of having intentionally re-written history we *want * to
414+ discard the commits on the remote and replace them with the new-and-improved
415+ versions from our local branch. In this case, what we want to do is ::
403416
404417 $ git push --force-with-lease
405418
0 commit comments