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 log -p vs. git show vs. git diff
  • Why did sourcetree delete my commit?
  • How to “attach” working dir to bare GIT repository
  • How to correctly checkout branches from a remote repository
  • Is it possible to get files from .git folder
  • Reference Git branch start commit
  • git and gerrit issue while review
  • List remote changes in git repository using JGit (a real diff)
  • How to change a github repo's directory to somewhere else?
  • Which layout to use for git-svn in a project with standard layout currently and non standard layout in past
  • How to fetch submodules in github
  • Including js from raw.github.com
  • 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.