A Git repository is the data structure that stores a project's complete history as a graph of commits, along with the files, branches, tags, and metadata needed to track and manage every change over time.
Key Points: • The .git directory holds the actual object database (commits, trees, blobs), references (branches, tags), and configuration for the repository. • Every commit forms part of a directed history graph, letting Git reconstruct the exact state of the project at any point in time. • A repository can exist purely locally, or be linked to one or more remotes for collaboration and backup. • Because every clone contains the full history, each one effectively acts as a complete backup of the project. • Repositories support branching and tagging natively, enabling parallel development and marking specific releases.
Example: Running git init in a project folder creates a hidden .git directory that becomes the repository, tracking every subsequent commit, branch, and tag made in that project from that point forward.
Code Example:
git init
git add .
git commit -m "Initial commit"Interview Tip: A concise interview answer is:
"A Git repository is the underlying data structure, stored in the .git directory, that tracks a project's full commit history along with its branches, tags, and metadata. Since every clone contains that complete history, each one is effectively a full backup of the project."