I recently realised the reference repository that our team pushes to was not configured to reject non-fast-forward updates.
Given the propensity of some team members to use history rewriting to clean up their contributions, without concern for whether these commits have been shared, I want to preserve every commit I will ever fetch from the reference repository in case I need to make an archeological investigation.
Of course, I can't afford to just reject these myself, or I'll be stuck in the past: I need to both keep the pre-rewrite history and get on board the post-rewrite one.
This procedure seems to work:
git fetchdoes not reveal any forced update, resume a regular activity.git update-ref -m "reverting forced update"git remote rename origin origin$COUNTERgit remote --set-url origin$COUNTER https://unreachable.example.com/origin$COUNTER/.gitgit remote add origin $REFURLgit fetch origingit branch -u origin/"$(git branch --show-current)"This works for me because I only have one local branch tracking any remote one at any given time: the current branch. Maybe two when I am made to make a quick fix before returning to my ongoing work, and only for the duration of that fix: I religiously delete local branches that track a remote one as soon as I have pushed that work and have switched to another branch. As a result, work at step 9 is very limited for me.