Git 101: The "Save Button" for Developers
What is GIT?
An easy way to describe Git is as a Distributed Version Control System (DVCS).
Think about writing a paper. Every time you make a big change, you might want to save the file as Essay_v1, Essay_v2, or Essay_Final_Final_Real. This is already done by Git, but in a much better way. Over time, it keeps track of the changes made to a file or group of files, so you can quickly find old copies.
Distributed: Instead of having all the files on one server, each worker has a full copy of the history of the project on their computer.
Version control keeps track of all the changes that have been made, so you can go back to earlier versions of your project.
Why is Git used?
One or more people can work on the same job at the same time and not erase what the other person has already done.
Logs and History: You can see a full record of who changed what and when. You can quickly go back to a version of the code that works if you break it.
Tests: You can try out new features on different branches without changing the code that works in the main branch.
Git Basics and Core Terminologies
You need to think about how Git works before you type commands.
The repository is the place where Git stores all of your project files. It's kind of like a log of everything that has happened with your project.
Commit: A picture of your project at a certain time. It's like a "Save Point" in a video game.
Branch: A separate copy of your library that works at the same time. Your code could live in a main branch, and you could try out new things in a feature branch.
HEAD: This is a link that tells you which branch and commit you are looking at right now. Most of the time, it leads to the most recent change made to your branch.
Common Git Commands
1. git init
Initializes a new Git repository. This command creates a hidden .git folder in your directory, turning it into a tracked repository.
2. git status
Checks the state of your working directory. It tells you which files are new, modified, or already staged for a commit.
3. git add
Moves changes from your working directory to the Staging Area. This tells Git, "I want to include these changes in the next save."
4. git commit
Captures a snapshot of the project's currently staged changes. Always include a clear message describing what you changed.
5. git log
Shows the commit history for the current repository. This allows you to see the list of changes made over time.
A Basic Developer Workflow
Let's go through a real-life example of how to start a project.
Step 1: Start the Project Open your terminal and create a new folder.
mkdir my-website
cd my-website
git init
Step 2: Create a File Create a simple text file.
echo "Hello World" > index.html
Step 3: Check Status See that Git notices the new file but isn't tracking it yet.
git status
# Output: Untracked files: index.html
Step 4: Stage the File Prepare the file to be saved.
git add index.html
Step 5: Commit (Save) the File Permanently save this snapshot to history.
git commit -m "Initial commit: Created index.html"
Step 6: Verify. Check your history to confirm the save.
git log

