DEV Community

Cover image for The Octopus Who Traveled Through Git Time
Werliton Silva
Werliton Silva

Posted on

The Octopus Who Traveled Through Git Time

Once upon a time, there was an octopus named Gity, who loved building sandcastles on a busy beach. Gity was a perfectionist: every time he built a tower, he took a picture of it with his magical camera called Git.

📸 Each photo was like a commit. He could look back and see how his castle evolved.

But one day, Gity made a mistake. He built a slightly crooked tower, took a photo anyway (made a commit), and later realized he needed to go back in time and fix that photo, without losing the new parts he had started building.

He was confused. How could he go back and edit an old photo without losing the new stuff?


🧠 Gity’s Plan (And Yours Too!)

plan

If you're like Gity and:

  1. Made a commit with a mistake;
  2. Already started working on new things;
  3. Want to go back in time, fix the mistake, and continue from where you left off...

...you can do exactly that with Git!


💾 Saving Your New Creations

Before going back in time, Gity used a magic chest called stash to temporarily store his current work:

git stash
Enter fullscreen mode Exit fullscreen mode

This saved his new changes without mixing them with the past.


⏪ Time Travel with Rebase

Then he told Git:

“Hey Git, let me edit that old commit back there!”

git rebase -i HEAD~3
Enter fullscreen mode Exit fullscreen mode

A list of photos (commits) appeared. He changed pick to edit on the one he wanted to fix.


🛠️ Making the Fixes

Gity fixed the crooked tower in the old commit (edited the file) and said:

git add .
git commit --amend
git rebase --continue
Enter fullscreen mode Exit fullscreen mode

Git gave a thumbs up and continued the timeline like nothing happened!


🎒 Getting Back What Was in the Chest

Now that everything was right, he opened the chest and brought back his new changes:

git stash pop
Enter fullscreen mode Exit fullscreen mode

And voilà! He was back in the present with everything in the right place. ✨


🚨 But When Sharing...

Gity wanted to send the new photos to his friends (do a git push), but Git said:

“Hey! Those old photos you changed are already on the wall! You have to tell me to replace them for real.”

So Gity said:

git push --force
Enter fullscreen mode Exit fullscreen mode

But only because he was alone on that wall. If others were working too, he would’ve talked to them first!


💡 The Moral of the Story

Git might seem tricky at first, but it’s like a magical sticker album: you can stick, remove, fix, stash new ones, and even time travel. You just need to know the right spells:

  • git stash → stores your changes;
  • git rebase -i → lets you edit the past;
  • git commit --amend → replaces a wrong sticker;
  • git push --force → tells the wall to update an old picture.

🙋‍♀️ What About You?

great

Have you ever needed to time travel with Git? Or were you scared of losing your sandcastle?

Share your story in the comments! If this helped, leave a ❤️ and save it for the next time Gitty the Octopus gets stuck in time!

Top comments (0)