Skip to content

Instantly share code, notes, and snippets.

@sibaJana
Forked from umayr/recover-deleted-branch.sh
Created May 28, 2023 20:40
Show Gist options
  • Select an option

  • Save sibaJana/c38f890614eb6b8f9607428f7ea96f5c to your computer and use it in GitHub Desktop.

Select an option

Save sibaJana/c38f890614eb6b8f9607428f7ea96f5c to your computer and use it in GitHub Desktop.
How to recover a deleted branch
## Pre-requisite: You have to know your last commit message from your deleted branch.
git reflog
# Search for message in the list
# a901eda HEAD@{18}: commit: <last commit message>
# Now you have two options, either checkout revision or HEAD
git checkout a901eda
# Or
git checkout HEAD@{18}
# Create branch
git branch recovered-branch
# You may want to push that back to remote
git push origin recovered-branch:recovered-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment