What happens if you accidentally delete a branch? (git)

What happens if you accidentally delete a branch?

I screwed up majorly yesterday. I finished a cool little plug. See below:

_config.yml

I wrapped up. And went to bed satisfied. The job was done!

But the next day, when I ran it, the code wasn’t working. It was confusing. So I had a look in Visual studio – and everything was a mess. Unfactored. I don’t exactly know how it happened, but I must not have properly merged back into the master branch.

I like to trim and delete branches after I’m done using them.

The question is: how do I get that branch back? It’s really simple:

Git reflog 

	// that will get you a whole bunch of SHAs.
	// You need to find the SHA that you are looking for.
	// Once you have found it check that branch out:
	// (you'll have to substitute your own)
	// unique branch name and the relevant
	// sha you need. example:

Git checkout -b new-branch-name c392j302
		
	// or in other words you can do:
	// the following:

Git checkout -b <branch> <sha>

It was a lot easier than I expected!

Hope that helps.

Written on March 10, 2017