Recover deleted branch in Git

This question already has an answer here:

  • Can I recover a branch after its deletion in Git?

    14 answers

  • git subtree split - the tags are not transferred
  • PHP Composer mixed with Git Submodules and Symfony2
  • git aliases causing “Permission denied” error
  • How to only get the name of files which changes are more than whitespaces?
  • Does using msysgit lead to repository corruption?
  • Examining a changeset in HG
  • Apply patches created with git log -p
  • How can I set up autocompletion for Git commands?
  • What does this disconnected arrow mean on gitk?
  • How to create digital object identifier (DOI) for bitbucket repository?
  • How do I log unique authors in git?
  • git server side hooks
  • 2 Solutions collect form web for “Recover deleted branch in Git”

    Create a list of all dangling or unreachable commits.

    git fsck --full --no-reflogs --unreachable --lost-found
    

    Print a list of commit messages for all commits in the lost and found.

    ls -1 .git/lost-found/commit/ | xargs -n 1 git log -n 1 --pretty=oneline
    

    Find your missing commit through the process of manual inspection (i.e. reading).
    Create a new branch with the missing commit as the branch head.

    git checkout -b branch-name SHA
    

    Having got the potential sha1 for the last tip of branch demo, use gitk sha1 to actually browse the commit’s history to check you have the right one.

    Git Baby is a git and github fan, let's start git clone.