Git Fundamentals in Three Days
Git Basics
A Safety Net for Your Work
Imagine you're writing a long research paper. You finish a paragraph, and it feels perfect. The next day, you decide to rewrite it, but your new version is a mess. If only you could go back to yesterday's draft! Most of us have been there. We might save multiple copies of the file, like paper_v1.doc, paper_v2.doc, and paper_final_for_real.doc. This is a basic form of version control.
A Version Control System (VCS) is a tool that automates this process, especially for complex projects like software. It tracks every change made to a project's files over time. If you make a mistake, you can rewind to a previous version. If you're working with a team, a VCS helps manage everyone's contributions without chaos.
Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.
Meet Git
Git is the most popular version control system in the world. It was created to help developers manage the massive codebase of the Linux operating system. Think of it as a super-powered time machine for your code.
You can think of GIT like a time machine for coding projects, it remembers every change you make and lets you go back if something breaks.
Git is a distributed version control system. This means that instead of one central server holding the project history, every developer has a full copy of the entire project history on their own computer. This makes it fast and flexible, allowing people to work offline and share changes directly with each other.
The Repository
When you use Git, your project lives inside a repository, often shortened to "repo." A repository is simply a directory, or folder, that contains all your project files and the entire history of changes. This history is stored in a special hidden sub-folder called .git.
To start tracking a project with Git, you first need to initialize a repository. You do this by navigating to your project's folder in the command line and running the git init command. This single command creates the .git sub-folder, and just like that, Git starts watching your files.
# Navigate to your project folder
cd my-project
# Initialize a Git repository
git init
The Three-Step Save
In Git, saving your work is a deliberate, three-step process. It's more than just hitting Ctrl+S. It involves moving your changes from your working files to a permanent spot in the project's history. The three areas are the Working Directory, the Staging Area, and the Repository.
1. Working Directory This is your project folder, where you create, edit, and delete files. Any changes you make here are just regular file edits until you tell Git about them.
2. Staging Area The staging area is like a draft of your next save. It's an intermediate step where you gather all the changes you want to group together into one snapshot. This lets you be very specific about what gets saved. For example, you might have edited three files, but you only want to save the changes from two of them. You would add just those two files to the staging area.
You use the git add command to move changes from your working directory to the staging area.
# Stage a specific file
git add index.html
# Stage all changed files
git add .
3. The Commit A commit is the act of taking the snapshot of everything in the staging area and saving it permanently to the repository's history. Each commit is a checkpoint. It has a unique ID and requires a descriptive message explaining what changes you made. Good commit messages are crucial for understanding the project's history later on.
You use the git commit command to create the commit.
# Commit the staged changes with a message
git commit -m "Add initial homepage content"
This three-step process—edit files, stage changes, commit snapshot—is the fundamental workflow you'll use constantly with Git.
Now you know the core concepts behind how Git tracks your work. You have a project folder (the repository) and a clear process for taking snapshots of your progress (commits).
