Created
February 3, 2022 16:06
-
-
Save NehaP09/36b583b03fcb671caf5bf4c7b036deb4 to your computer and use it in GitHub Desktop.
Recover deleted remote branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I accidentally deleted a git branch from both local and remote and also refreshed the page so the "recover" option was gone. | |
I didn't lose any code, since I had a backup copy. | |
But I did lose the commit history. | |
I was left with all code changes from all 16 commits in a folder. | |
This is what I did to recover the deleted local and dev branch: | |
1. git checkout master | |
2. git reflog | |
3. obtain the SHA of the top/latest commit on the deleted branch | |
4. get out of the reflog mode | |
5. there are 2 ways here: | |
a. if you want to also rebase the deleted_branch_name to master do this: | |
git branch <deleted_branch_name> <top_commit_SHA> | |
b. if you don't want to push the commits from master to deleted_branch_name do this: | |
git checkout -b <deleted_branch_name> <top_commit_SHA> | |
6. git push origin <deleted_branch_name> | |
And voila! My heart was no longer in my mouth! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment