If I run git branch -d XYZ, is there a way to recover the branch? Is there a way to go back as if I didn’t run the delete branch command?
If I run git branch -d XYZ , is there a way to recover
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, you should be able to do
git reflog --no-abbrevand find the SHA1 for the commit at the tip of your deleted branch, then justgit checkout [sha]. And once you’re at that commit, you can justgit checkout -b [branchname]to recreate the branch from there.Credit to @Cascabel for this condensed/one-liner version and @Snowcrash for how to obtain the sha.
If you’ve just deleted the branch you’ll see something like this in your terminal
Deleted branch <your-branch> (was <sha>). Then just use that<sha>in this one-liner: