2

I accidently deleted most branches in origin repo (Github) by using git push -f --mirror

which i didnt really understood what it did.

Is there any way i can reverse what i did and get back all branches in origin?

I dont have any information about these branches since i didnt work with them.

EDIT: On closer look Gits response message looks like this

`- [deleted] 001

`- [deleted] 002_hide_ticketFilters

`- branches ommited for brevity

`* [new branch] CR/002_hide_ticketFilters -> CR/002_hide_ticketFilters

`* [new branch] origin/001 -> origin/001

`* [new branch] origin/002_hide_ticketFilters -> origin/002_hide_ticketFilters

`* rest ommited for brevity

It says new branch for every branch that was deleted. But i cant see these brancehs anymore. Not on my computer and not going to github either.

EDIT: So ive saved the list of all the branches that where deleted if that helps.

Daarwin
  • 2,896
  • 7
  • 39
  • 69
  • 1
    Do you still have them on your local? – Chukwuemeka Inya Aug 26 '18 at 11:57
  • NO! What i did , i think, was to mirror local to origin. So it deleted all the branches from origin that is not in local :'( – Daarwin Aug 26 '18 at 11:58
  • Check this link out. https://stackoverflow.com/questions/1992364/git-recover-deleted-remote-branch – Chukwuemeka Inya Aug 26 '18 at 12:01
  • My Git-fu is not strong enough to really determine if that case is similar to mine. – Daarwin Aug 26 '18 at 12:05
  • OK... Let me experiment and get back to you ASAP. – Chukwuemeka Inya Aug 26 '18 at 12:07
  • Oh man. I am so gratefull. Updating OP with some more info now... – Daarwin Aug 26 '18 at 12:07
  • Ok... From the Q/A, I am sure your branches are still there somewhere. So, do, `git reflog` – Chukwuemeka Inya Aug 26 '18 at 12:51
  • i did just git reflog and i got logged info going backwards in time. Im not sure what to do with it. The branches deleted in origin where never in my local. – Daarwin Aug 26 '18 at 12:59
  • I did the reflog on my local. Am i supposed to do it in the remote where the branches where deleted? Not sure how to reflog the remote. – Daarwin Aug 26 '18 at 13:07
  • Oh... Let's try this then...Github right? – Chukwuemeka Inya Aug 26 '18 at 13:21
  • You are to do it on your local. – Chukwuemeka Inya Aug 26 '18 at 13:22
  • Yes Github. I have all the names of the deleted branches. They where deleted in from the origin remote and have never been in my local. – Daarwin Aug 26 '18 at 13:22
  • Ok i did git reflog in my local What should i do with the information. I dont seem to see anything there about the deleted brancehs on the remote repo. – Daarwin Aug 26 '18 at 13:23
  • Cool. Try this: `curl -i https://api.github.com/repos/YourUsername/ProjectName/events`. What's the response? – Chukwuemeka Inya Aug 26 '18 at 13:26
  • Sorry i dont recognize that. Its not a git command? Anyway i get a { "message": "Not Found", "documentation_url": "https://developer.github.com/v3/activity/events/#list-repository-events" } – Daarwin Aug 26 '18 at 13:32
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/178795/discussion-between-chukwuemeka-inya-and-lautaro). – Chukwuemeka Inya Aug 26 '18 at 13:35
  • 1
    If you were able to find a solution in chat, I would be interested in hearing about your solution. :) – Git.Coach Aug 27 '18 at 14:43
  • 2
    Also, and this is for everyone, **please** stop using `git push -f` if you don't know what it is doing. **Please**! Almost every post here on Stack Overflow where people ask about how to recover things seems to stem from people using `git push -f` without knowing what it does. `git push -f` is **not** meant to be used in regular workflow, it is a fix-my-critical-issue tool. – Lasse V. Karlsen Aug 28 '18 at 08:43
  • @LasseVågsætherKarlsen so true! Problem is, when you dont know what it does and someone tells you to use it as a fix.... – Daarwin Aug 28 '18 at 08:44
  • 2
    The same advice goes to those giving advice, if you don't understand what `git push -f` does, or don't know if the person you're giving it to understands it, or you know what the exact effect will be, **don't give that advice**. Just stop. People give that advice and don't even stop to ask if the person receiving the advice is in a team. Numerous posts here where people messed up, someone said "just clean up and use `git push -f`" whereas the next post is "my colleague complains that I removed his work, halp!". – Lasse V. Karlsen Aug 28 '18 at 08:44

1 Answers1

2

Its solved.

Since the repo was in Github normal ways to revover was not possible since reflog cant be accessed. Github have an api that can act as reflog but its not the same thing.

In this case the only way to solve it was to get in touch with Github support that helped me by providing a list with SH1As.

Daarwin
  • 2,896
  • 7
  • 39
  • 69