What Is a Git Repository? Local vs Remote Repositories Explained
A Git repository (commonly called a "repo") is a digital directory structure containing all your project files alongside the complete historical record of every change ever made to them.
💡 Plain-English Analogy
When you tell Git to track a folder on your computer, that folder becomes a Git repository. Git creates a hidden magic drawer inside that folder named ".git" where it secretly stores every single snapshot and version you ever commit.
⚙️ Architecture & Under the Hood
The `.git` directory contains the object database (blobs, trees, commits, and annotated tags), reference pointers (HEAD, local branch refs, remote tracking refs), the staging index, and configuration files. Cloning a repository downloads the full history graph, enabling autonomous offline operations.
Creating and Syncing Repositories
You can initialize a brand new repo locally or clone an existing repo from a remote server.
# Initialize a new Git repository in the current folder
git init
# Link local repository to a remote GitHub repository
git remote add origin https://github.com/username/project.git
# Clone an existing remote repository to your machine
git clone https://github.com/username/project.git
Frequently Asked Questions
What is a "bare" repository in Git?
A bare repository is a Git repository without a working directory (it contains only the contents of the .git folder). Bare repos are used exclusively on central servers (like GitHub) to store and receive pushes without allowing direct file editing.