DEV Community

Cover image for Gitmarillion ep 1: One Ring to manage them all: Introduction to Git and VCS
Riccardo Solazzi
Riccardo Solazzi

Posted on • Originally published at gitmarillion.thezal.dev

Gitmarillion ep 1: One Ring to manage them all: Introduction to Git and VCS

If you're just starting with Git and version control (VCS), you probably feel like Frodo when he receives the One Ring: powerful, yet unaware of what that power entails. Don't worry! In this article, I'll guide you through the basics of Git while journeying through the wonderful land of the Shire.

What is a Version Control System (VCS)??

Dwarves

Everyone knows that, despite Bilbo's best efforts to keep unexpected guests out of his home, someone always ended up showing up unannounced. And if that "someone" happened to be a rowdy group of dwarves looking for a place to eat, drink, and make merry, having at least one copy of his precious manuscript, There and Back Again, was essential.

A VCS is a system that records changes made to a file or a set of files over time so that you can recover specific versions later, preventing the loss of your work. In other words, a VCS allows you to keep track of changes in a project over time, making it possible to revert to previous versions, compare modifications, collaborate with others, and potentially recover lost work.

Git: the One Ring

The Ring

Git is an extremely powerful tool, capable of shaping and controlling code much like the One Ring controlled the fates of Middle-earth. As a VCS, Git keeps track of all the changes made to a project (code in our case, paragraphs in Bilbo’s). Additionally, Git enables collaboration with other authors, keeping track of who made which changes—helping you figure out if someone like Pippin tampered with the precious manuscript, and allowing you to recover a previous version if needed.

Just like the Ring forged by Sauron, Git gives you control over your project, providing complete visibility over its evolution and the ability to modify it as you see fit. But beware: with great power comes great responsibility. Misusing Git—such as writing a poorly structured commit or making a faulty merge—can wreak havoc on your code, much like the Ring could corrupt even the purest hearts.

Git's true strength lies not only in its power but in the user's ability to understand its mechanisms and use them wisely. If you master it, you'll have a formidable ally to manage your code with precision and confidence. Just like Frodo on his journey, your task is to learn how to use this tool without being overwhelmed by its complexity.

The Beginning of the Journey: Basic Commands

Running Bilbo

To start your journey with Git, you only need to learn a few basic commands. Here’s a list of the most useful ones:

git init: this command adds files to the staging area, a sort of transit area where Git keeps track of files that will be included in the next commit.

git add andata_e_ritorno.txt: this command creates a commit, essentially a snapshot of your project at that moment. Each commit has a message describing it, making it easy to understand what was changed.

git commit -m "writing chapter 1: an unexpected journey": this command creates a commit, essentially a snapshot of your project at that moment. Each commit has a message describing it, making it easy to understand what was changed.

git status: this command shows the status of the repository, indicating which files have been modified, which have been added to the staging area, and which have been committed.

git log: this command displays the list of commits made in the repository, allowing you to see what changes were made and by whom.

git remote add origin https://github.com/Bilbo/there-and-back-again.git: this command links the local repository to a remote repository, enabling you to share your code with others.

git push origin main: this command pushes your commits to the remote repository, making them available to other contributors.

Conclusions

Like Frodo, your journey may seem daunting at first, but with practice, you'll become a master of code management and learn to wield the power of the One Ring! Git will help you safeguard your work, collaborate with other developers, and never lose your code to chaos again.

Top comments (0)