Git says my branch and origin diverged, how do I not lose two days of work Debug Help
I committed locally, someone else pushed to the same branch, and now git pull prints a message about divergent branches and refuses to do anything. I have two days of commits that are not pushed anywhere. I do not want to type a command I do not understand and find out my work is gone. What is the safe order of operations here?
@vacuum_analyze · 7mo ago · 3 replies
First, breathe, committed work is very hard to actually lose. Before anything else make a safety copy of the branch pointer:
That costs nothing and means every commit you have is reachable by name no matter what happens next.
Then pick one of two things.
git pull --rebasereplays your commits on top of theirs and gives you a clean straight line, which is what most teams want.git pull --no-rebasemakes a merge commit, which is uglier in the log but never rewrites your commits. Both are safe. If a rebase goes sideways mid conflict,git rebase --abortputs you exactly back where you started.Reply
Report
@threat_modeler_j · 7mo ago
Also
git reflogis the undo history for basically everything. Even after a bad reset you can find the old commit hash there for a good while.Reply
Report
@backfill_bram · 7mo ago
The backup branch trick is worth the whole thread. Rebased, three conflicts, all in one file, done in ten minutes.
Reply
Report