Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,293,521
Community Members
 
Community Events
165
Community Groups

git push origin --mirror deleted all of my colleagues branches

Hi All,

 

I've just stupidly done a

git push origin --mirror

which mirrored my local repo to the remote deleting all of my colleagues work. Is there any way to revert to the remote repo state before I pushed my local repo?

Cheers

1 answer

 

One idea:  get every colleague to just type "git checkout [branch]" and "git push" for every branch that matters to them.  They probably all have reasonably up-to-date local copies on their own machines.

Are you on Bitbucket Server or Bitbucket Cloud?  If you're on Bitbucket Server you might be able to painstakingly recover the lost branches by sifting through the server logs and recovering the commitId / branch associations.  Under the hood nothing is lost, but it can take days of menial (and error prone) log searching to recover the labels.

In the future, if you're on Bitbucket Server I recommend installing our free Control Freak for Bitbucket Server add-on, since it blocks pushes like this on the server-side right out of the box thanks to this setting (which defaults to enabled):

Block Multi-Rewrites [x] Yes [ ] No
Avoid push.default=matching disasters

With that setting in place your push would have (probably) been blocked with a warning like this:

remote: -----
remote: Push rejected. Multiple history rewrites
remote: in a single push not allowed.
remote:
remote: Is your "push.default" config is set to "matching"?
remote: Try setting it to "simple" instead.
remote:
remote: Trying to mirror a repo? In that case, disable
remote: "Control Freak for Bitbucket Server" for this repository.
remote: (Repository Settings -> Control Freak)
remote: -----

 I say "probably" because the push would have had to contain at least two history rewrites, which is highly likely with a "git push --mirror".   In future versions of Control Freak we plan to have this logic improved to also catch accidental "git push --mirror" scenarios that have no history rewrites.

Thanks for your reply. I think using fail safes in the future is a must and I will let our admin know about control freak. Atlassian have reverted the repo back to its original state from one of their automatic backups so all is good now!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,095 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you