1. Introduction to version control

How Git works

The functionality of Git revolves around efficiently managing project files and tracking their changes over time. Unlike traditional version control systems that track changes to each file, Git considers your codebase as a series of snapshots of a miniature filesystem. Let's break down how Git operates.

Three main states of files in Git

  1. Working tree (also known as the working directory). This is your actual work files in their current state. It's the version of your project that you see and work on.

  2. Staging area (also known as the index). When you're finished with your work, it's time to "snapshot" the changes and store this snapshot in the repository permanently. In Git terms, such a snapshot is called a commit. The staging area is where you prepare your changes for the next commit. It exists because you might not want to commit all the changes you've made since the last commit. The staging area lets you group related changes into a single commit.

    For example, if you developed a simple feature, but in the process you also fixed a typo in a comment, you can commit these changes separately, because these changes are unrelated. Otherwise, if you commit them together, and later need to revert the feature, you'll also revert the typo fix.

  3. Repository. Once you commit your changes, they become a part of the Git repository. You can think of the repository as a database of all the changes you've made to your project over time. It's the complete history of your project, and it's where Git stores all the snapshots of your project.

    The repository is stored in the .git directory in your project's root directory. Keep in mind that this directory is hidden by default. Damaging or deleting this directory will corrupt your local repository.

Git workflow

The typical Git workflow involves:

  • Modifying files in your working directory. In other words, doing your actual work.

  • Preparing changes for the commit. You select and add changed files to the staging area.

  • Committing staged changes. Git takes the files as they are in the staging area and stores that snapshot permanently in your Git repository.

  • (optionally) Syncing your changes with a remote repository, such as GitHub. Push your commits or pull the updates added by others.

Sounds complicated?
Let's look at an example
© 2024-2025 GitByBit.All rights reserved.

Hi! I'm Alex, creator of GitByBit.

This page is a part of the interactive course about Git version control.

It's a one-of-a-kind course that is integrated into the VS Code code editor. Learning directly in VS Code lets you operate Git exactly as you would in real life, doing real jobs, writing real code.

In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.

The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.

Learn Git in VS Code