DEV Community

Spooktober: Git Horror Story

Pabi Moloi, but Forbes on October 28, 2018

Since it is the month of all things spooky, I thought it would be a good idea to post one of my scary experiences while developing, to get into t...
Collapse
 
rhymes profile image
rhymes • Edited

It felt embarrassing, as I am a junior dev. And I've been working with git commands for 3 years so far.

Don't worry, we all forget commands :-)

The thing is git clone creates a copy of the repository on your local machine pointing to the HEAD. In this copy you have the entire history and all the branches, develop included.

Once cloned you could have switched branch from master to develop by issuing: git checkout develop

git clone -b develop URL is, I think, a shortcut of the two commands.

Collapse
 
moopet profile image
Ben Sinclair

Once cloned you could have switched branch from master to develop by issuing: git checkout develop

That's what they described doing, isn't it?

Collapse
 
rhymes profile image
rhymes

Yeah, I forgot about the origin part :-)

Johanathan's answer is more complete

Collapse
 
thomaswdmelville profile image
Thomas Melville

I've been working with git for 6 years now and I've had some major nightmares over the years. Hours or days of code gone in one swift enter key stroke.

I've learnt one git command that's since saved me from those nightmares:


git reflog 

It keeps a local history of all the changes to a repo. So even if you screw up your branch, the commit is still there and can be found and restored using reflog.

Collapse
 
ben profile image
Ben Halpern

Nice takeaways

Collapse
 
pabiforbes profile image
Pabi Moloi, but Forbes

Hey Ben,
Thank you for taking the time to read.