r3plica r3plica - 1 year ago 197
Git Question

Restore remote Git branch

Before i go any further, let me explain why we can't do a:

git checkout -b <branch> <sha>

Basically the branch (let's call it dev1) was on another developer's machine. He had done some commits and pushed them up. This branch was branched from another branch (we can call this Features) that was being renamed to development.
development was created as a branch of Features and then features was deleted.
The developer's branch (dev1) was then deleted by the other developer both locally and remotely. When using github for windows he found that all the branches we asking to be pushed, so he deleted the entire folder (which skipped the recycle bin) and re-cloned the repo.
So now he can't do a:

git reflog

because it doesn't have any history. I can't see his commits because they were never pulled locally onto my machine.

So, with that in mind, is there a way of restoring his dev1 branch remotely?
I have been looking for a command that would show all remote branches that were deleted, but thus far, have been unable to find such a command.

Any help will avoid weeks of development work!

Answer Source

You can use the GitHub Events API to see the last 300 events (paginated in 30 events per page) occured during the last 90 days for a user or for a repo. There you can search for the last push event on that branch and thus get the SHA-1 that you need to reinstantiate as branch.

E. g. here you can see my recent events: https://api.github.com/users/Vampire/events, https://api.github.com/users/Vampire/events?page=2, a. s. o.

or here the events for the repository vivin/gradle-semantic-build-versioning: https://api.github.com/repos/vivin/gradle-semantic-build-versioning/events, https://api.github.com/repos/vivin/gradle-semantic-build-versioning/events?page=2, a. s. o.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download