DEV Community

Pabi Forbes
Pabi Forbes

Posted on

Spooktober: Git Horror Story

Header Image

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 the mood of Spooktober.
This scary experience comes in the form of git. So here's the story...

I was placed on an Android project, where I had to add a new feature and apply flavour specific resources. So the first thing to do was to clone the project. Alright, I've done that before so it shouldn't be an issue. Oh was I wrong. The project source resides on BitBucket and I make use of Git Bash terminal to clone and to run other commands. I go to BitBucket and choose the develop branch (see image below), then proceeded to press the "Clone" button, pasted the link into my terminal.
develop branch

The develop branch on BitBucket.

At this point, all seems well. I then proceed to Android Studio to open up the project to make sure that it builds. The project runs a successful build. I go back to my terminal again to run $git status to see the status of the branch I'm currently in. I then noticed that I'm in master. I then run $git checkout develop . It returns a message that states that the branch does not exist.
How can this be possible as it exists on BitBucket.

I repeat the whole process again, hoping for a different outcome. I still encounter the same issue. I ask a colleague if he has a successful clone. He says no. I then wonder if we were given the correct access rights on BitBucket...
But that wouldn't be the cause because I could view all of the branches. At this point I'm too shy to approach my manager for this silly situation.
Next step: Dig up solutions on Stackoverflow.

I Googled my issue, found some suggested solutions on Stackoverflow. The first few solutions didn't work at all. I digged deeper, and finally a solution that worked. The command is $git clone -b .

Some of the reasons why I did not approach my senior/team lead initially was because:

  1. I wanted to should show attempts in trying to solve my issue.
  2. It felt embarrassing, as I am a junior dev. And I've been working with git commands for 3 years so far.

Lessons to take away:

  1. Attempt to solve an issue before you approach a team mate.
  2. Do not spend too long on trying to solve an issue.
  3. Alert your team mates of the issue in time.
  4. Share your solutions with the community.

Which git commands do the trick for you?

Useful links:

Cover Photo by Ehud Neuhaus on Unsplash

Top comments (8)

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 Forbes

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

Some comments may only be visible to logged-in visitors. Sign in to view all comments.