Skip to main content
In this lesson, you will learn how to initialize a local Git repository for your project. This step is essential for tracking changes and collaborating with teams. First, open your terminal, navigate to your project folder, and run the following command:
This command creates a hidden .git directory containing all of Git’s tracking information for your project. To confirm that the repository was created correctly, list all files in the directory (including hidden ones) with:
Next, add a new file to your project. In this example, we will create a simple text file called story1.txt that contains a short sentence. Execute the following commands:
Even though you have created the file, Git is not yet tracking it. To check the current status of your repository, run:
The status output indicates that you are on the default branch (master) and that story1.txt is untracked. Untracked files are those that Git recognizes but has not been added to the staging area.
Before committing, always add your new or modified files to the staging area with git add.
To start tracking your new file, add it to the staging area:
With the file now staged, you’re ready to commit your changes. Always include a concise and descriptive commit message when committing. For example:
This commit records the current state of your project in your local Git repository. It serves as a reference point for you and your teammates, allowing you to revert to this state if necessary. By following these steps, you have successfully initialized a Git repository and made your first commit. This foundation is crucial for efficient version control and collaboration throughout your project’s lifecycle.

Watch Video