3. Putting the project under version control

Initializing a repository

We're about to initialize our first repository! I hope you didn't close the terminal yet, because we're going to use it for something important.

The command to create a new repository is git init. This command creates a new empty repository in the current directory. Run the following command in your terminal to initialize the new repository:

Let's do it!
Task

Run the git init command in the VS Code terminal.

If everything went according to plan, you should see something like this as an output of the command:

Result:
Initialized empty Git repository in /home/your-user-name/gitbybit/.git

This means that changes in our project can now be tracked by Git.

Anything else?

The repository itself is located in a hidden directory named .git. Because it's hidden, you won't see it in the file explorer by default. However, you can see it in the terminal by running the ls command with the -Force-a option. Keep in mind that if something happens to the .git directory, the repository will be corrupted.

Everything else in the root directory of the project is usually called the working tree (or the working directory). Think of the directories and files in your project branching out like limbs on a tree—that's why Git uses the word tree here. It's the place where you do all the work, create and edit files, etc. The files in the working tree can differ from what you saved in the repository. For example, you can have a file in the working tree that is not yet in the repository. You can tell Git to either save the changes in the repository or discard them.

By the way, you might have noticed some changes in the VS Code interface after we initialized the repository. The SOURCE CONTROL panel is now connected to our new repository. In the corner, you can also see the name of the current branch (we'll talk about branches later).

git init in VS Code

In fact, the SOURCE CONTROL panel is a graphical interface to the Git repository. For the sake of practice, in this course we will only be using the terminal to interact with the repository. But in real life, many common operations, such as adding or committing files, can be done faster using the graphical interface.

Next step
© 2024-2026 GitByBit.All rights reserved.