Git? Why do I keep Hearing About It?

Git? Why do I keep Hearing About It?

An intro to Git, an essential tool for every developer

Welcome to this Multiverse of Code series where we will be exploring the wonders of git. A tool used by countless developers in their everyday coding life. In part one of the series we will be looking at:

  • What is Git?
  • Why should you care?
  • How Git is used.

We will not jump right into working with git just yet. This part is meant to give you a high level of understanding of what Git is and why you need it in the first place. Let's get right into it :).

What Is Git?

Git is an open-source version control system used for managing changes in projects. These projects are usually referred to as repositories (repos). You can think of git as a tool used to control the timeline for your code. You can create new timelines, delete timelines or merge multiple timelines. What this means is, when you are working on a project, you can use git to mark certain points as you progress with the project. These "checkpoints" mark the timeline for the project.

Why Should You Care?

If you're new to coding, you've probably been hearing people tell you "learn git it's important" or "learn git, thank me later". Well those people are not wrong but you're probably asking yourself, what does git do? and why is it so useful? and why must I use it as well?. Let me give you a few scenarios to clear your mind.

  • You wake up one morning and all the files for a project you've been working on for months have been deleted. What do you do? Panic attack? NO. With Git, just a single command can restore your project to its previous state, hence saving your job and potentially your life. LOL.

  • You're working on a website and you want to try out a new design but you also want an easy way to come back to the current design. I think this is one of the founding reasons why we have version control systems today. Using git, you can try out new ideas in your project without having to worry about messing up your entire project where you need to start painfully deleting stuff hoping the project works again.

  • You're part of a team and all team members are working on the same project. Git makes collaboration less painful. It has features that help team members work on different parts of a project at the same time and later merge the work into the final product.

Hopefully, now you see how important git is and why so many developers use it. Now let's explore how people use git in their daily life.

How Git Is Used

Using git at first might be tricky but can easily be picked up with practice. Git commands are usually run from the command line (command prompt/terminal) but can be run from a GUI app. Obviously, this means understanding how to use the command line is important for working with git. Let's look at some common workflows in git.

The Commit Workflow

At the heart of git is "saving" changes to your project which are called commits. Commits are how you create checkpoints in your project which ultimately make up the timeline. Of course, git doesn't automatically make these commits for us. We need to tell git we've made changes and we want git to keep a record of the current state of the project in case we need to come back to it. A change in git doesn't have to be in just one file. As a matter of fact, in most cases, it isn't. A change is a modification of file(s) which we can group under a single commit accompanied by a message summarising the changes.

Here's an example: Imagine you're working on a website and you just finished creating the navigation bar. Probably you had to work in the HTML and CSS files to get the navbar done. These changes can be grouped into a single commit which you can title "create navbar" which summarises what you did. This is how you tell git to keep track of your project.

However, committing happened in two phases, the staging phase, and the committing phase. The staging phase is simply the point where you tell git what files in your project you want to group to make a commit. This is helpful because maybe you made changes to your project in two files that do not relate to one another. You can separate the two changes into different commits by staging the first change, which tells git to make a checkpoint(commit) with the first change then staging the next and making another checkpoint.

Making Branches

Branches are a feature of git that allows you to try out multiple ideas in parallel on your project. A branch is just like an alternate timeline of your project where you can continue working in a different direction. However, you still have the main timeline (branch) of your project which you can go back to at any time. Changes made in branches can later be merged into the main timeline. Developers usually use this feature during collaboration such that multiple developers work on different parts of a project concurrently and later merge their different timelines to make the main project timeline with every feature implemented. Cool right?

Committing and Branching are the two most important features of git but not everything. There are other features of git like stashing and rebasing but those are less likely to be used often in your daily workflow.

That's it, guys. Hopefully, this article gave you a high-level overview of what Git is and why you need it. My goal with this was to make you understand the purpose of git such that you know why you need to learn it. See you on the next one :).