0 votes
1 view
in Devops and Agile by (20k points)

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?

1 Answer

0 votes
by (28.4k points)

Yes, it is possible. By using git reflog find the SHA1 for the commit at the tip of your deleted branch, then just git checkout [sha]. And once you're at that commit, you can just git checkout -b [branchname] to recreate the branch from there.

Following command will do the magic

$ git checkout -b <branch> <sha>

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...