Project Initiator – Create Local Repository (git init)

How to Create a Local Repository with git init

The first step to launch a Git project is to run the git init command. The command will create a Local Repository in the current working directory.

This command doesn't require any options or arguments. You need to simply run the following command in the directory where you want to generate a new project.

Command Line - INPUT
git init

After running the command, a Local Repository is created under a hidden directory named .git. If you cannot see it, you need to make hidden directories and files visible. For Mac, press the ⬆︎ shift + ⌘ command + . keys.

Practice

bloovee-round-icon.pngDeveloper A (Project Owner Role)

Objective:
Create a Git Local Repository

1. Setup a practice project directory and file for this chapter

Target directory and file structure

For this practice, we'll use the following directory and file. The directory and file will be used throughout the practices in this chapter and the next chapter.

  • Practice project directory: git_practice
  • Practice file: git_practice.html

The screenshot below is the target directory structure example based on Mac OS.

Create a Git Local Repository with VS Code: Step 1

Create the practice project directory and file

Open the project's main directory (e.g., Dev_A_bloovee) with VS Code. You can use drag & drop to open the directory.

Create a Git Local Repository with VS Code: Step 2

After opening the project's main directory with VS Code, open a new terminal in the VS Code window.

Make sure that your current working directory in the command line is the project's main directory (e.g., Dev_A_bloovee)...

Create a Git Local Repository with VS Code: Step 3

...and run the commands below to create the directory and file.

Command Line - INPUT
mkdir git_practice
cd git_practice
touch git_practice.html

2. Create a Local Repository

To create a Local Repository, run the git init command in the git_practice directory.

Command Line - INPUT
git init

You'll see the message as shown below. On Windows, you may not see the hint messages.

Command Line - RESPONSE
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint:   git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint:   git branch -m <name>
Initialized empty Git repository in /Users/bloovee/git_practice/.git/

After running the command, one hidden directory named .git is created. This is the place where the Local Repository is created.

Create a Git Local Repository with VS Code: Step 4