This project is a minimal implementation of Git, developed in Python, that replicates core functionalities of the distributed version control system. It serves as a learning tool to understand how Git works under the hood, including how it stores and manipulates data.
-
Repository Management:
- Create and initialize Git repositories.
- Manage
.git
directories with essential metadata and configurations.
-
Object Storage:
- Implement object storage using SHA-1 hashing for blobs, trees, and commits.
- Store and retrieve objects in Git's compressed format.
-
Basic Git Operations:
init
: Create a new repository.add
: Stage changes by adding files to the index.commit
: Record staged changes in a commit object.log
: View commit history.cat-file
: Inspect Git objects (e.g., blobs, commits).
-
Branching:
- Create and switch between branches.
- Manage references for branch heads.
-
Learning Tool:
- Provides detailed insights into Git’s internal structure and concepts like blobs, trees, commits, and refs.
- Python (version 3.7 or later)
-
Clone this repository:
git clone https://github.com/SpideR1sh1/Git-Clone.git cd wyag
-
Run the script directly:
python wyag.py
wyag init
: Initialize a new Git repository.python wyag.py init
-
wyag hash-object
: Create a blob object and store it.echo "Hello, WYAG!" | python wyag.py hash-object -w
-
wyag cat-file
: Inspect objects in the repository.python wyag.py cat-file blob <SHA-1>
-
wyag add
: Add files to the staging area.python wyag.py add <filename>
-
wyag commit
: Create a new commit.python wyag.py commit -m "Initial commit"
wyag log
: View the commit history.python wyag.py log
-
wyag branch
: Create or list branches.python wyag.py branch <branch_name>
-
wyag checkout
: Switch to a branch.python wyag.py checkout <branch_name>
.
├── wyag.py # Main script implementing Git functionality
├── objects.py # Handles Git objects (blobs, trees, commits)
├── repository.py # Manages repository initialization and configuration
├── utils.py # Utility functions for file I/O and hashing
└── README.md # Documentation
- Initializes a
.git
directory containing objects, refs, and configuration files.
- Objects (blobs, trees, commits) are hashed using SHA-1 and stored in a compressed format in
.git/objects/
.
- Stages changes by creating a temporary index file.
- Commits reference staged changes and previous commits.
- Branches are managed using references in
.git/refs/heads/
.
- Understand Git’s internal workings: object storage, indexing, and branching.
- Explore the data structures (blobs, trees, commits) that form the backbone of Git.
- Learn how Git efficiently tracks changes and manages history.
python wyag.py init
echo "Hello, WYAG!" > file.txt
python wyag.py add file.txt
python wyag.py commit -m "Added file.txt"
python wyag.py log
python wyag.py cat-file blob <SHA-1>
- Add support for merging branches.
- Implement
diff
to view changes between commits. - Extend
log
to show graphical commit trees.
- Sincere thanks to Thibault Polge, whose “Write Yourself a Git” tutorial served as an invaluable learning resource and foundation for this implementation.
This project is licensed under the MIT License.