Question
Accidentally deleted remote branch while trying to rename my master branch to main. Is there any way to restore it?
Recently, while trying to rename my master branch to my main branch on my remote github repo, I mistakenly followed a tutorial. I didn't read the tutorial thoroughly, and ended up deleting the master branch entirely, without any of the changes ending up on the main branch on the remote.
The commands I ran were the following:
git branch -m master main //renames
git fetch -p origin
git branch -u origin/master main
git remote set-head origin -a
git branch -D master
git push origin :master
Is there any way to undo the last command to delete the remote branch. Unfortunately, I can't see any evidence of the master branch from github? I can only see that the master branch has been deleted in the git command line. I have changes on the remote branch where I directly edited the README file, but I never edited the README locally, so I can't restore it locally I think. Is there any way I can restore the branch remotely through Github?
I tried running git checkout -b master origin/master
to get back any remainings of the origin/master branch, but it seemed to not work. I also tried git reflog
to see if I can identify any README commits, but unfortunately I can only see commits related to my local changes.
Unfortunately, I made README changes on the remote without doing it on local for the easier UI experience on Github. I can restore the local changes, but I spent quite a bit on the README, so I would love if I could restore that as well.