Help, I deleted a branch I still needed
Deleting a branch only deletes the label. Put it back on its last commit and everything is there again.
git branch -D feature/login Deleted branch feature/login (was cdc3c7a).
The fix
git reflogOnly needed if the hash has scrolled away. The branch's last commit is on the line just below “checkout: moving from feature/login to …”, not on that line itself.
git branch feature/login cdc3c7aRecreates the branch on that commit, using the hash Git printed when it deleted the branch.
feature/login is an example. Replace it with your own.
git branch feature/login cdc3c7aBefore
After
Why this works
A branch is just a name for a commit. git branch -D removes the name, but the commits stay in the repository for weeks. Git even printed the last commit's hash when it deleted the branch. If that has scrolled away, the reflog has it. And if the branch was pushed before, git switch feature/login simply recreates it from the remote.