> For the complete documentation index, see [llms.txt](https://gitdeveloperguide.solomonmarvel.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitdeveloperguide.solomonmarvel.com/git-fundamentals/git-basics-practice-scenarios/initialising-a-git-repository.md).

# Initialising a Git Repository

<mark style="color:blue;">Scenario</mark>

Say you're working on a new project and you decide to setup version control in order to map out the history of the project, collaborate and better manage your development workflow over time. Here's a sample pattern to approach this usecase:

Step 1: **Creating a New Directory**&#x20;

Before initialising a Git repository, you need to create a new directory to hold your project files. You can do this using the `mkdir` command in your terminal or command prompt:

```bash
mkdir my-project
```

Step 2: **Navigating into the Project Directory**&#x20;

Navigate into the newly created directory using the `cd` command:

```bash
git init
```

After running this command, Git will create a hidden `.git` directory inside your project directory. This directory contains all the necessary metadata and objects to manage your repository.

Step 4: **Verifying the Initialisation**

To verify that the repository was successfully initialised, you can use the `ls` command with the `-a` flag to show hidden files:

```bash
ls -a
```

You should see the `.git` directory listed among the files and directories.

Step 5: **Staging and Committing Files**&#x20;

Once the repository is initialised, you can start tracking changes to your project files. Let's assume you have some existing files in your project directory. To begin tracking them, you need to add them to the staging area using the `git add` command:

```bash
git add file1.txt file2.txt
```

This command stages `file1.txt` and `file2.txt` for the next commit. You can replace these filenames with the actual files in your project.

Step 6: **Creating the Initial Commit**&#x20;

After adding the files to the staging area, you can create the initial commit using the `git commit` command. This command permanently saves the changes you have staged:

```bash
git commit -m "Initial commit"
```

The `-m` flag is used to provide a commit message describing the changes made in the commit. You can customise the commit message according to your project's needs.

{% embed url="<https://youtu.be/dDKwjMufmz4>" %}

{% hint style="success" %}
Congratulations! You have successfully initialised a Git repository and created the initial commit for your project.
{% endhint %}
