git Folder
Structure
.git/ # Main directory storing all Git-related data
│── HEAD # Points to the current branch (e.g., ref: refs/heads/main)
│── config # Stores repository-specific configuration settings
│── description # Used by GitWeb to describe the repository (not used in local Git)
│── index # Stores the staging area (information about tracked files)
│── packed-refs # Stores packed branch and tag references (for performance optimization)
│
├── hooks/ # Contains scripts to automate actions before or after Git events
│ ├── pre-commit # Runs before a commit is created (e.g., for code linting)
│ ├── post-commit # Runs after a commit is created (e.g., for notifications)
│ ├── pre-push # Runs before pushing to a remote repository
│ ├── update # Runs when updating references on the remote repository
│ ├── ... # Other sample hook scripts (can be customized)
│
├── info/ # Repository metadata and exclusion rules
│ ├── exclude # Local repository-specific .gitignore-like file
│
├── objects/ # Stores all Git objects (blobs, trees, commits, tags)
│ ├── info/ # Contains performance-related metadata
│ ├── pack/ # Stores compressed objects for performance
│ ├── xx/ # SHA-1 named directories storing actual Git objects
│
├── refs/ # Stores references to commits (branches, tags, remotes)
│ ├── heads/ # Stores branch references (e.g., main, feature-branch)
│ │ ├── main # Reference file for the 'main' branch (contains the latest commit hash)
│ │ ├── feature-branch # Reference for a feature branch
│ ├── tags/ # Stores tag references (lightweight and annotated tags)
│ ├── remotes/ # Stores remote branch references
│ ├── origin/ # Remote repository tracking branch
│ ├── main # Latest known commit on the remote 'main' branch
│
├── logs/ # Stores history of reference changes (branch checkouts, commits)
│ ├── HEAD # Keeps track of branch switching and commits
│ ├── refs/ # Logs for specific branches
│ │ ├── heads/ # Local branch history
│ │ ├── remotes/ # Remote branch history
│
Contents
HEAD
- Purpose: Points to the currently checked-out branch.
- Location:
.git/HEAD - Contents: Typically contains a reference like
ref: refs/heads/main, which tells Git which branch is currently active.
config
- Purpose: Stores repository-specific configuration settings.
- Location: .git/config
- Contents: Includes settings like remote repositories, user information, and merge behavior.
description
- Purpose: Used by GitWeb (a web interface for Git) to describe the repository.
- Location: .git/description
- Contents: A simple text description. Has no effect on repository behavior.
hooks
- Purpose: Contains scripts for automating actions before or after certain Git events (e.g., commits, pushes, or merges).
- Location:
.git/hooks/ - Example Hooks:
pre-commit– Runs before a commit is created.post-commit– Runs after a commit is made.pre-push– Runs before a push operation.
info
- Purpose: Contains metadata about the repository, including ignored files.
- Location:
.git/info/ - Contents:
exclude– A local.gitignorefile that applies only to this repository.
objects
- Purpose: Stores all the data (blobs, trees, commits, and tags) in a compressed format.
- Location:
.git/objects/ - Structure:
objects/info/– Optional, used for performance optimization.pack/– Stores packed objects for efficiency.- SHA1-named directories (e.g., e9/) – Each file inside is a Git object.
refs
- Purpose: Stores references to commits, such as branches and tags.
- Location:
.git/refs/ - Contents:
heads/– Contains branch references (e.g.,.git/refs/heads/main).tags/– Stores tag references.remotes/– Contains remote-tracking branches.
logs
- Purpose: Keeps a history of reference changes (like branch checkouts).
- Location:
.git/logs/ - Contents:
HEAD– Tracks changes to theHEADreference.refs/heads/– Logs branch updates.refs/remotes/– Logs remote-tracking branch changes.
index
- Purpose: A staging area (cache) for changes before committing.
- Location:
.git/index - Contents: A binary file containing information about the working tree.
packed-refs
- Purpose: Optimizes repository performance by storing references in a single file instead of multiple files.
- Location:
.git/packed-refs - Contents: Contains packed branch and tag references.