A toy Git clone written in Go for learning the fundamentals of version control
Follow these steps to get kitkat up and running on your local machine
Note: Doesn't support any remote commands
Before you begin, make sure you have the Go programming language installed You can download it from the official Go website
-
Clone the Repository First, get a local copy of the project using
git clonegit clone https://github.com/LeeFred3042U/kitkat.git
-
Navigate into the Directory Move into the project folder you just cloned.
cd kitkat -
Build the Executable Compile the Go source code. This command creates a runnable program named
kitkatin your current directorygo build -o kitkat ./cmd/main.go
Note: If you do not add the executable to your system's PATH (step 4), you must run the command with
./kitkatfrom within this directory (e.g.,./kitkat init) -
(Optional) Add to Your System's PATH To use the
kitkatcommand from anywhere, move the executable to a location in your system'sPATH# For Linux or macOS sudo mv kitkat /usr/local/bin/
Before you start using kitkat, you should set your name and email. This information will be used in your commits
# Set your name
kitkat config --global user.name "Your Name"
# Set your email
kitkat config --global user.email "you@example.com"You can get help directly from the command line
General Help
To see a list of all available commands and their summaries, use the help command
kitkat helpSpecific Command Help
To get detailed usage information for a specific command, add the command's name after help
kitkat help add
kitkat help commit- Repository Initialization: Create a new
.kitkatrepository - Staging Area: Add new, modified, or deleted files to the index
- Commit History: View a log of all commits
- Branching & Merging: Create and switch between branches, and perform fast-forward merges
- Status & Diff: Check the status of your working directory and view colorized diffs
- Global Config: Set user information like name and email
KitKat is an educational toy project designed to mimic the core functionality of Git. It operates on the same fundamental principles of version control, taking snapshots of your project. Each snapshot is built from three key objects:
- Blobs: The content of your files
- Trees: The directory structure that organizes blobs
- Commits: A pointer to a tree, representing the state of your project at a specific point in time, linked to a parent commit to form a history
Initializes a new, empty KitKat repository in the current directory.
kitkat initAdds file contents to the staging area (index). It can stage specific files or all changes.
# Stage a specific file
kitkat add <file-path>
# Stage all new, modified, and deleted files
kitkat add --allShows the commit history for the current branch.
# Show the detailed, multi-line history
kitkat log
# Show a compact, single-line view
kitkat log --onelineDisplays the state of the working directory and the staging area. It shows which files are staged, unstaged, and untracked.
kitkat statusShows the colorized differences between the last commit and the staging area.
kitkat diffManages branches. Running it without arguments lists all branches. Providing a name creates a new branch.
# List all local branches
kitkat branch
# Create a new branch named 'new-feature'
kitkat branch new-featureSwitches branches, checks out a specific commit (detached HEAD), or restores a file to its last committed state.
# Switch to the 'new-feature' branch
kitkat checkout new-feature
# Checkout a specific commit hash (detached HEAD)
kitkat checkout <commit-hash>
# Revert a file to its state in the last commit
kitkat checkout <file-path>Joins another branch's history into the current branch. Currently only supports fast-forward merges.
kitkat merge <branch-name>Shows a simple list of all files currently in the staging area.
kitkat ls-filesRemoves untracked files from the working directory. Requires a -f flag for safety.
# Show which files would be removed (dry run)
kitkat clean
# Forcefully remove untracked files
kitkat clean -fGets or sets the global user configuration, such as name and email.
# Set your name
kitkat config --global user.name "Your Name"
# Get your name
kitkat config --global user.name
# Set your email
kitkat config --global user.email "you@example.com"
# Get your name
kitkat config --global user.emailNote- kitkat diff: Currently acts like git diff --staged (compares Index vs HEAD). Standard git diff compares Workdir vs Index. kitkat merge: Currently behaves like git merge --ff-only. It will succeed if the merge is a Fast-Forward, but it will fail (by design, for now) if a true 3-way merge is required.