DEV Community

Cover image for An explanation of Git for beginners
Avi Avinav
Avi Avinav

Posted on • Updated on

An explanation of Git for beginners

Git is an essential tool for version control, no matter what programming language or framework you use. That's a pretty okay explanation but when I first heard about Git, I didn't understand what that meant, might be the case for you too.

An analogy

Now, let's say there was a man, Lorem Ipsum, who was living a pretty good life, he had a loving dog, a good job, and a nice house; but then he messed up a lot of things, his dog ran away, he lost his job and now he is on drugs wishing every day that he could go back in time and fix his mistakes, but that is only a wishful fantasy, he doesn't have a time machine.

Don't worry though, you don't have to end up like Lorem, because you've got Git, your time machine. Of course, it cannot fix all your mistakes in life but it can let you return to a certain checkpoint in the timeline of your project.

Let's say, I wasn't using Git. I started building a web app, and everything's going well, but then I try to center a div and it's all messed up. I keep trying to fix it but I can't. Finally, I deleted the project and start it again from scratch, and the same story repeats. I abandon the project and question my life choices, then cry myself to sleep. Based on a true story.

But then I started using Git, so whenever I add a new feature I set a checkpoint by making a commit and adding a comment about the change for future reference. So, even if I mess up in the future and can't get back, I won't have to cry myself to sleep. I can just use Git and go back to that checkpoint.

You can also use it to create an alternate timeline called a branch. Your branch would be named master or main by default. Now, when you create an alternate branch, it copies everything from the default branch into this one, let's call this branch "dev" (you can call it whatever). In this branch, you can do whatever you like and it won't affect the "main" branch, and when you are satisfied with your work on the "dev" branch, you can open something called a pull request (as the name suggests a request to pull changes from one branch to another) and then merge (basically means accepting a pull request) it in with your "main" branch to update it.

Installation

Git is installed by default on most Linux & Mac machines. In case, it isn’t, you can use brew or apt-get to install it.

For windows users, you can download and use the installer from git-scm.com, if you have scoop you can use that, or you can use winget.

Other useful tips

Use these tips once you know what the basic commands in Git do.

  • To save time you can set up an alias for Git in your terminal, I have set mine to just "g" (Yeah, I really saved a lot of time, didn’t I?). It's easy to do, just check it according to your terminal.
  • You can also create a global .gitconfig file and add aliases for commands like st for status.

More Info

I won’t be discussing git commands here, I intended this article to only be about what git is and why you should use it.

Hope you were able to gain something from this article.

Discussion (5)

Collapse
zyabxwcd profile image
Akash

Wow. You wrapped it up pretty quickly. It was good though. I can imagine that this would click right away with a beginner.

Collapse
aviavinav profile image
Avi Avinav Author

Thanks for the kind words 😊

Collapse
aviavinav profile image
Avi Avinav Author

This is my first post here on dev.to I hope you like it. Please feel free to advise me on how I can improve.

Collapse
navineha profile image
navineha

Awesome post!

Collapse
aviavinav profile image
Avi Avinav Author

Thanks!