Git Repository Basics
Understanding Git Repositories
Git repository is a core concept in version control and source code management. It represents a directory where Git tracks and manages all project files, changes, and version history. Each repository contains a complete set of project files and the entire revision history.
Repository Types
Repository Type |
Description |
Use Case |
Local Repository |
Stored on personal computer |
Individual development |
Remote Repository |
Hosted on online platforms |
Team collaboration |
Bare Repository |
Contains only version history |
Central storage |
Creating a Git Repository
## Initialize a new repository
mkdir my-project
cd my-project
git init
## Create initial commit
touch README.md
git add README.md
git commit -m "Initial project setup"
Repository Structure
graph TD
A[.git Directory] --> B[Objects]
A --> C[Refs]
A --> D[Config]
A --> E[HEAD]
The .git
directory contains all metadata and version control information. Key components include:
- Objects: Store file contents and commits
- Refs: Store branch and tag references
- Config: Repository-specific configuration
- HEAD: Current branch pointer
Key Repository Commands
## Check repository status
git status
## View commit history
git log
## List all branches
git branch -a
These commands help developers understand repository state, track changes, and manage project versions effectively.