Git - Avoiding and Dealing with Unwanted Deletes In Remote Repo


How do avoid? Slow down. Slow is smooth and smooth is fast. Before you push know take your time and know exactly what that push is going to do. Test it in contained lab environment if you don't know what it does. Use git wrapper script to interact with https://github.com/rchain/rchain


Git - What to do when an unwanted deletes happen in a remote repo like deleted branches?

  • Try and restore branches from previously open pull requests in github web interface. Go to Pull Requests(tab) and then specific pull request. There are two buttons to click on Open pull request(button) at bottom of page.  There will be another button restore PR button by 
  • push existing local branch back to remote repo.

Note: If you pull and see that your stuff is gone revert to previous commit and push that up to your branch


Example:

Wanted to just push my working local in entirety to my github repo. Did git push --mirror. and it ended up deleting stuff from upstream. Didn't look close enough at what it was doing.

In this case, noted in block below, the push caused unwanted push to rchain/rchain and deleted branches that user was able to.

Screen scrape:

root@maximus:~/code/rchain# git remote set-url --push origin https://github.com/jeremybusk/mirrored-test
root@maximus:~/code/rchain# git remote -v
origin git@github.com:jeremybusk/rchain (fetch)
origin https://github.com/jeremybusk/mirrored-test (push)
upstream git@github.com:rchain/rchain (fetch)
upstream git@github.com:rchain/rchain (push)
root@maximus:~/code/rchain# git push --mirror
Counting objects: 7, done.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 801 bytes | 0 bytes/s, done.
Total 7 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
remote: error: GH006: Protected branch update failed for refs/heads/dev.
remote: error: Cannot delete a protected branch
To git@github.com:rchain/rchain
- [deleted] dev-eitan&kyle-spatial
- [deleted] dev-eitan-docs
- [deleted] dev-eitan-readmes
- [deleted] dev-griff-core-88
- [deleted] dev-kent-build-readme
- [deleted] dev-kent-ubuntu-14.04
- [deleted] revert-70-dev-kent-build-readme
- [deleted] spatial
* [new branch] OPS-35 -> OPS-35
* [new branch] origin/HEAD -> origin/HEAD
* [new branch] origin/OPS-35 -> origin/OPS-35
* [new branch] origin/dev -> origin/dev
* [new branch] origin/dev-eitan&kyle-spatial -> origin/dev-eitan&kyle-spatial
* [new branch] origin/dev-eitan-docs -> origin/dev-eitan-docs
* [new branch] origin/dev-eitan-readmes -> origin/dev-eitan-readmes
* [new branch] origin/dev-griff-core-88 -> origin/dev-griff-core-88
* [new branch] origin/dev-kent-build-readme -> origin/dev-kent-build-readme
* [new branch] origin/dev-kent-ubuntu-14.04 -> origin/dev-kent-ubuntu-14.04
* [new branch] origin/master -> origin/master
* [new branch] origin/revert-70-dev-kent-build-readme -> origin/revert-70-dev-kent-build-readme
* [new branch] origin/spatial -> origin/spatial
* [new branch] upstream/dev -> upstream/dev
* [new branch] upstream/dev-eitan&kyle-spatial -> upstream/dev-eitan&kyle-spatial
* [new branch] upstream/dev-eitan-docs -> upstream/dev-eitan-docs
* [new branch] upstream/dev-eitan-readmes -> upstream/dev-eitan-readmes
* [new branch] upstream/dev-griff-core-88 -> upstream/dev-griff-core-88
* [new branch] upstream/dev-kent-build-readme -> upstream/dev-kent-build-readme
* [new branch] upstream/dev-kent-ubuntu-14.04 -> upstream/dev-kent-ubuntu-14.04
* [new branch] upstream/master -> upstream/master
* [new branch] upstream/revert-70-dev-kent-build-readme -> upstream/revert-70-dev-kent-build-readme
* [new branch] upstream/spatial -> upstream/spatial
! [remote rejected] dev (protected branch hook declined)
error: failed to push some refs to 'git@github.com:rchain/rchain'
root@maximus:~/code/rchain# 


More Reference Material

https://stackoverflow.com/questions/3640764/can-i-recover-a-branch-after-its-deletion-in-git

"You should be able to do git reflog and find the SHA1 for the commit at the tip of your deleted branch, then just git checkout [sha]. And once you're at that commit, you can just git checkout -b [branchname] to recreate the branch from there."

https://www.atlassian.com/git/tutorials/undoing-changes

https://github.com/blog/2019-how-to-undo-almost-anything-with-git