0

I accidentally deleted git branch using:

  "git delete -D branchName" 

is it possible to recover this branch?

Jannat Arora
  • 2,559
  • 5
  • 39
  • 64
  • See https://stackoverflow.com/questions/3640764/can-i-recover-a-branch-after-its-deletion-in-git – Stuart Mar 18 '19 at 12:39
  • @Stuart The question asked in the post is about "git delete -d" which is local delete, whereas I have mistakenly done "git delete -D" which is remote delete – Jannat Arora Mar 18 '19 at 13:12
  • @JannatArora No, this is a misunderstanding. `-D` has nothing to do with remote deletion, it's an entirely local operation. The difference between `-d` and `-D` is the check for unmerged commits in the branch, which is overridden in the latter case. – Romain Valeri Mar 18 '19 at 13:13

1 Answers1

0

Use git reflog to get the SHA of the deleted branch and the git checkout to restore it.

full explanation can be found here: How to move HEAD back to a previous location? (Detached head) & Undo commits

CodeWizard
  • 110,388
  • 20
  • 126
  • 153
  • I did a "git delete -D" which is remote delete. I know the SHA of deleted branch..will this work in my case too – Jannat Arora Mar 18 '19 at 13:13
  • `git delete -D` has nothing to do with remote deletion. It is just a shortcut for `--delete --force`. `-d` allows you to delete only fully merged branches, while with `-D` you can delete whatever branch you want. – Arnaud Christ Mar 18 '19 at 13:15