Skip to main content
March 23, 2026Dan Rodney/3 min read

Create a New Local Git Repository (Initialize Repository)

Master Git repository initialization and version control fundamentals

Understanding Git Repository Components

Project Files

Your actual working files and folders that make up your project. These remain visible and editable in your normal file system.

Revision History

Complete timeline of all changes made to your project. Git tracks every modification, addition, and deletion over time.

Git Metadata

Hidden .git folder containing all tracking information. This subfolder manages version control behind the scenes.

Hidden Files on macOS

The .git folder is hidden by default on Unix-based systems. Use Cmd-Shift-Period to toggle visibility of hidden files in macOS Finder, though you rarely need to access this folder directly.

Git Repositories

A Git repository (or repo for short) serves as the central nervous system of your project—it contains all of your project files plus the complete revision history of every change ever made. Think of it as a sophisticated time machine for your code. You'll take an ordinary folder of files (such as a website's root folder) and tell Git to transform it into a repository. This creates a hidden .git subfolder that contains all the Git metadata responsible for tracking changes, managing branches, and maintaining your project's entire evolutionary history.

On Unix-based operating systems such as macOS and Linux, files and folders that start with a period (.) are automatically hidden from normal view. This means you won't see the .git folder in the macOS Finder or most file managers unless you explicitly show hidden files—but rest assured, it's working behind the scenes. This design choice keeps your project directory clean while Git operates invisibly in the background. The good news is you'll rarely, if ever, need to directly access the .git folder, as Git's command-line tools and GUI interfaces handle all the heavy lifting.

TIP: On macOS you can toggle the visibility of hidden files by pressing Cmd+Shift+Period(.)—a handy shortcut for those moments when you need to peek under the hood.

What Happens When You Initialize a Repository

1

Folder Selection

Choose any ordinary folder containing your project files, such as a website's root directory or application source code.

2

Git Initialization

Tell Git to convert the folder into a repository, enabling version control and change tracking capabilities.

3

Metadata Creation

Git creates a hidden .git subfolder containing all necessary metadata and configuration files for tracking changes.

Regular Folder vs Git Repository

FeatureRegular FolderGit Repository
Change TrackingNoneComplete history
File RecoveryLimitedFull version history
CollaborationFile sharing onlyMerge and branch support
Backup StrategyManual copiesDistributed version control
Recommended: Git repositories provide comprehensive version control that regular folders cannot match.

Initialize a Git Repo

Now that you understand what a Git repository is, let's walk through the process of creating one. Visual Studio Code makes this remarkably straightforward with its integrated Git support, which has only improved since Microsoft's continued investment in developer tooling.

  1. Open a project folder in Visual Studio Code.

    You can do this by going to File > Open (Mac) or File > Open Folder (Windows), navigate to the folder containing your project files, select it, and hit Open (Mac) or Select Folder (Windows). Alternatively, you can drag and drop the folder directly onto the VS Code icon or use the command line with code . if you have the VS Code command-line tools installed.

  2. Open the Source Control panel vscode soure control icon on the left sidebar of the VS Code interface.
  3. In the Source Control panel vscode soure control icon, click the Initialize Repository button.

    VS Code will immediately create the .git folder and set up the initial repository structure. You'll notice the Source Control panel transforms to show your project files as "untracked changes"—these are files that Git now sees but hasn't been told to monitor yet. This is the first step in bringing your project under version control, setting the stage for tracking changes, collaborating with team members, and maintaining a professional development workflow.

Step-by-Step Repository Initialization in VS Code

1

Open Project Folder

Navigate to File > Open (Mac) or File > Open Folder (Windows). Browse to your project directory and select it.

2

Access Source Control

Locate and click the Source Control panel icon in the left sidebar of the VS Code interface.

3

Initialize Repository

Click the 'Initialize Repository' button in the Source Control panel to convert your folder into a Git repository.

Visual Studio Code Integration

VS Code provides seamless Git integration through its Source Control panel. This visual interface eliminates the need for command-line Git operations during initial setup.

Pre-Initialization Checklist

0/4

Key Takeaways

1A Git repository transforms an ordinary folder into a version-controlled project with complete revision history tracking
2The hidden .git subfolder contains all metadata necessary for Git operations but requires no direct user interaction
3Repository initialization creates the foundation for version control without modifying your existing project files
4Visual Studio Code provides integrated Git support through its Source Control panel, eliminating command-line complexity
5Hidden files on macOS can be toggled with Cmd-Shift-Period, though accessing the .git folder is rarely necessary
6Git repositories enable advanced features like branching, merging, and collaboration that regular folders cannot provide
7Proper folder selection before initialization ensures your entire project structure is included in version control
8The Source Control panel in VS Code offers a user-friendly interface for Git operations including initial repository setup

RELATED ARTICLES