Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Git Directory and Working Tree | Introduction to Git
course content

Зміст курсу

Git Essentials

Git Directory and Working TreeGit Directory and Working Tree

Congratulations! You've just created a local Git repository for your project. As we previously mentioned, running the git init command also creates a hidden .git directory. Now, it’s time to discuss this directory in more detail.

Git Directory

Let’s first run the ls -la command to list all files and directories (including hidden ones starting with a dot) within our project directory:

Here, you can see that our project directory indeed contains the hidden .git directory. If you are not already in the project directory , use the cd command to change your current working directory to it.

Note

All of the three entries of the list start with the d character indicating that the entry is a directory.

Now, let's run the ls -l .git command to list all regular (non-hidden) files and directories within the .git directory:

Once again, the first three entries, starting with the - character are regular files and the last four entries, as we have already mentioned, are directories. As for now, however, we won’t discuss these files and directories. Moreover, we will use commands to interact with them instead of directly manipulating them.

Project directory

Basically, you can treat the .git directory as the centralized database for your project, responsible for storing changes and their history. Once again, when you initialize a new repository using git init, a new .git directory is created. Similarly, when you clone a repository, this .git directory is copied to your local machine.

Working Tree

Let’s now discuss the concept of "working tree". The working tree (working directory) is a directory which represents the current state/version of your project, where you perform any modifications you want.

Note

The working tree contains all the files and folders outside the .git directory.

Let's take a look at the visualization to make things clear:

Project directory

Here, we can clearly see that the .git directory doesn't contain the working tree.

The working tree comprises all the files currently tracked by Git, as well as any new files that haven't been added to the list of tracked files yet. The following command is used to check the state (status) of our working tree:

Let’s now run the git status command for our working tree:

As for now, our working tree is empty since our project directory is empty.

Все було зрозуміло?

Секція 1. Розділ 6
course content

Зміст курсу

Git Essentials

Git Directory and Working TreeGit Directory and Working Tree

Congratulations! You've just created a local Git repository for your project. As we previously mentioned, running the git init command also creates a hidden .git directory. Now, it’s time to discuss this directory in more detail.

Git Directory

Let’s first run the ls -la command to list all files and directories (including hidden ones starting with a dot) within our project directory:

Here, you can see that our project directory indeed contains the hidden .git directory. If you are not already in the project directory , use the cd command to change your current working directory to it.

Note

All of the three entries of the list start with the d character indicating that the entry is a directory.

Now, let's run the ls -l .git command to list all regular (non-hidden) files and directories within the .git directory:

Once again, the first three entries, starting with the - character are regular files and the last four entries, as we have already mentioned, are directories. As for now, however, we won’t discuss these files and directories. Moreover, we will use commands to interact with them instead of directly manipulating them.

Project directory

Basically, you can treat the .git directory as the centralized database for your project, responsible for storing changes and their history. Once again, when you initialize a new repository using git init, a new .git directory is created. Similarly, when you clone a repository, this .git directory is copied to your local machine.

Working Tree

Let’s now discuss the concept of "working tree". The working tree (working directory) is a directory which represents the current state/version of your project, where you perform any modifications you want.

Note

The working tree contains all the files and folders outside the .git directory.

Let's take a look at the visualization to make things clear:

Project directory

Here, we can clearly see that the .git directory doesn't contain the working tree.

The working tree comprises all the files currently tracked by Git, as well as any new files that haven't been added to the list of tracked files yet. The following command is used to check the state (status) of our working tree:

Let’s now run the git status command for our working tree:

As for now, our working tree is empty since our project directory is empty.

Все було зрозуміло?

Секція 1. Розділ 6
some-alt