Skip to content

Instantly share code, notes, and snippets.

@expandables-dev
Forked from umayr/recover-deleted-branch.sh
Created September 25, 2023 04:44
Show Gist options
  • Save expandables-dev/635cea94750c2c5b84b063e8ad351e76 to your computer and use it in GitHub Desktop.
Save expandables-dev/635cea94750c2c5b84b063e8ad351e76 to your computer and use it in GitHub Desktop.

Revisions

  1. Umayr Shahid created this gist Apr 1, 2016.
    15 changes: 15 additions & 0 deletions recover-deleted-branch.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    ## 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