Back to Tutorials

Creating a Local Git Repository

What is a Git Repository?

A Git repository is a storage space where all the files, version history, and metadata of a project are managed using Git. Git tracks changes made to files over time, makes sharing of source code easier, maintains a history of changes, and reverts to previous versions if needed.

What is a Local Git Repository?

A local Git repository is a Git repository stored on your computer. It is created when you initialize a Git project using the git init command or clone an existing repository using git clone.

How to Create a Local Git Repository?

1. Navigate to your source code directory

In my tutorial, Structuring Python Project Directories, we set up a dedicated folder to store the source code. Let us use the Gen EMR project as an example. Open up your terminal and navigate to the directory below:

1
2
3
| - gen_emr/
    | - gen_emr_src/  --> Open up this directory.
    | - gen_emr_venv/

2. Create a local git repository

Type the following command in your terminal:

1
git init

This command creates a hidden .git folder where Git stores its data (like commit history and branch information).

1
2
3
4
| - gen_emr/
    | - gen_emr_src/
        | - .git  --> New
    | - gen_emr_venv/

3. Configure the email address and name that will be used for your Git commits.

If you work on multiple projects and need to use different email addresses for each project (for example, a personal email for your own projects and a work email for your job), you can configure the email address on a per-repository basis using the --local setting.

1
2
git config --local user.name "Your Full Name"
git config --local user.email "your.email@domain.com"

You may find other tutorials using the --global setting. These settings apply to all repositories for the current user on the machine and are stored in the user's home directory in the .gitconfig file. On Windows, you can find that in the following directory: C:\Users\your_username\.gitconfig.

4. Confirm that the Git was configured successfully.

Entering the following command in your terminal:

1
2
git config user.name
git config user.email

You should be able to see the following:

1
2
Your Full Name
your.email@domain.com

Note: If you navigate outside the Git repository, such as moving to the root directory (i.e., gen_emr/), the repository-specific settings will no longer apply. In this scenario, your global setting takes over. In the same vein, when you run git config --list, it will display the name and email configured in your global Git settings, along with other configuration details.