Okay, you've successfully installed and configured Git. Now, let's get down to business and start tracking a project. Whether you have an existing project you want to place under version control or are starting a brand new one, the first step inside your project's main directory is to initialize a Git repository.
The command to do this is git init
.
This command creates a new subdirectory named .git
right within your project folder. This .git
directory is the heart of your repository; it contains all the necessary files and metadata Git needs to track changes, manage history, store configuration settings, and more. Essentially, everything that makes your project a Git repository lives inside this hidden directory. Your actual project files, often called the "working directory" or "working tree," remain alongside it.
Let's walk through an example. Imagine you have a directory for a new website project called my-website
.
First, navigate into your project directory using the command line:
cd path/to/my-website
Make sure you replace path/to/my-website
with the actual path to your project folder.
Now, run the git init
command:
git init
Git will respond with a message confirming the initialization:
Initialized empty Git repository in /path/to/my-website/.git/
And that's it! Your my-website
directory is now a Git repository. Although it doesn't look much different on the surface, Git is now ready to start tracking your work within this folder.
The .git
directory is hidden by default on most operating systems. To see it, you can use the ls -a
command on Linux or macOS, or dir /a
on Windows Command Prompt:
# On Linux or macOS
ls -a
# On Windows Command Prompt
dir /a
You should see .git
listed among your project's files and directories (if any exist yet).
Directory structure comparison before and after running
git init
. The command adds the hidden.git
directory, which contains the repository's metadata.
It's important to understand that git init
creates a local repository. It doesn't automatically connect to any remote hosting service like GitHub. It simply sets up the necessary infrastructure on your own computer for Git to start managing your project's versions. You only need to run git init
once per project.
With the repository initialized, you can now begin the core Git workflow: adding files to the staging area and committing snapshots of your project, which we'll cover next.
© 2025 ApX Machine Learning