Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 82932e8

Browse filesBrowse files
committed
DOC: add diagram and explanation
1 parent 446eff4 commit 82932e8
Copy full SHA for 82932e8

File tree

Expand file treeCollapse file tree

1 file changed

+28
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-15
lines changed

‎doc/devel/development_workflow.rst

Copy file name to clipboardExpand all lines: doc/devel/development_workflow.rst
+28-15Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -376,30 +376,43 @@ to replace your already published commits with the new ones.
376376
Pushing, with force
377377
-------------------
378378

379+
379380
If 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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.