Git Directory and Working Tree
You have just created a local Git repository for your project. As mentioned earlier, running the git init command also creates a hidden .git directory. Now, explore this directory in more detail.
Git Directory
Run the ls -la command to list all files and directories, including hidden ones that start with a dot, inside your 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.
All of the three entries of the list start with the d character indicating that the entry is a directory.
Run the ls -l .git command to list all regular (non-hidden) files and directories inside the .git directory:
The first three entries that start with the - character are regular files, and the last four entries are directories. For now, these files and directories will not be discussed in detail. You will use commands to interact with them rather than modifying them directly.
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
The working tree (or working directory) is the directory that represents the current state or version of your project. It is where you make all modifications and updates to your files.
The working tree contains all the files and folders outside the .git directory.
Take a look at the visualization to make this concept clear:
The .git directory does not include the working tree.
The working tree contains all files currently tracked by Git, along with any new files that have not yet been added to tracking. Use the following command to check the state (status) of the working tree:
Run the git status command to check the state of your working tree:
The working tree is empty because the project directory does not contain any files yet.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.57
Git Directory and Working Tree
Swipe to show menu
You have just created a local Git repository for your project. As mentioned earlier, running the git init command also creates a hidden .git directory. Now, explore this directory in more detail.
Git Directory
Run the ls -la command to list all files and directories, including hidden ones that start with a dot, inside your 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.
All of the three entries of the list start with the d character indicating that the entry is a directory.
Run the ls -l .git command to list all regular (non-hidden) files and directories inside the .git directory:
The first three entries that start with the - character are regular files, and the last four entries are directories. For now, these files and directories will not be discussed in detail. You will use commands to interact with them rather than modifying them directly.
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
The working tree (or working directory) is the directory that represents the current state or version of your project. It is where you make all modifications and updates to your files.
The working tree contains all the files and folders outside the .git directory.
Take a look at the visualization to make this concept clear:
The .git directory does not include the working tree.
The working tree contains all files currently tracked by Git, along with any new files that have not yet been added to tracking. Use the following command to check the state (status) of the working tree:
Run the git status command to check the state of your working tree:
The working tree is empty because the project directory does not contain any files yet.
Thanks for your feedback!