On Tue, Jul 4, 2023 at 3:44 PM Junio C Hamano <gitster@xxxxxxxxx> wrote: > > On 02/07/2023 21:08, Alex Henrie wrote: > >> Many times now, I have seen novices do the following: > >> 1. Start work on their own personal topic branch > >> 2. Push the branch to origin > > And did this succeed, or did this fail? I'd assume that it failed, > because othrewise you would not be rebasing your work done in #1 on > top of what the central repository has. Also ... It succeeded; the new branch was created on origin. > >> 3. Rebase the branch onto origin/master > > ... the user's better have done "git fetch" to update origin/master > before this step. And that means this can just be done with "git > pull --rebase" (or you may already have configured pull to do so). Yes, the rebase was performed with `git pull -r origin master`. Other work had been done on master while the topic branch was being worked on. > In any case, assuming that this was indeed the intention of the > user, i.e. the user never wanted to discard the changes made in the > central repository (presumably by others)... The user did not want to discard anything from master, but they absolutely did want to discard the obsolete version of their own branch, which they made themself. > >> 4. Try to push again, but Git says they need to pull > > ... if this happened, it is because somebody else pushed in the > meantime, right? Then ... No one pushed between steps 3 and 4. > >> 5. Pull and make a mess trying to reconcile the older topic branch with > >> the rebased topic branch > > ... this means that somebody else's work was something that > overlapped with what you did in #1, and then you do want to clean up > the mess carefully, so that you do not lose the work by that > somebody else. So ... The conflicts came from trying to reconcile an older version of the user's work with a rebased version of the user's work. The user doesn't want to end up with a history that has two commits from the same author with the same message. > >> Help avoid this mistake by giving advice that mentions > >> force-pushing, > > ... why would it possibly be a good idea to suggest force pushing, > which discards other's work? I do not quite understand. The user was only trying to overwrite the old version of their own branch, which no one cares about. This scenario comes up commonly when using a single shared remote repository, or when using a forked remote repository and running `git pull -r upstream master` to incorporate changes from the upstream remote repository. I hope that's more clear now. Please let me know if it's not. -Alex