Restore an accidentally deleted branch
git recover deleted branch | undo git branch -D | accidentally deleted branch | git | branch | restoreCaution: This command changes the system. Understand what it does before you run it.
git branch feature/contact-form a1b2c3dCreates the branch again and points it at the given commit, which brings back the branch’s complete history. git branch -D prints the hash right when deleting (Deleted branch ... (was a1b2c3d)). If that output is gone, git reflog helps, as it lists the last checkout of the branch with its hash.
Note: This only works as long as the commits have not been removed by garbage collection. If the branch still exists on the remote, git switch with the branch name is enough.
Also searched as
- git recover deleted branch
- undo git branch -D
- accidentally deleted branch