#3 Git for Beginners: Basics and Essential Commands
Think of Git as a high-powered "Undo" button and a "Time Machine" combined into one. Whether you are working on a simple HTML project or a massive application, Git ensures you never lose your progress.
1. What is Git?
Git is a Distributed Version Control System.
Version Control: It keeps track of every change you make to your code. If you make a mistake today, you can jump back to exactly how the code looked yesterday.
Distributed: Every developer has a full copy of the project history on their own computer, not just on a central server.
2. Why is Git Used?
In the old days, programmers would save files like index_v1.js, index_v2_final.js, and index_v3_REAL_final.js. This was a nightmare.
Git solves this by:
Collaboration: Multiple people can work on the same file at the same time without overwriting each other's work.
Safety: You can experiment with new features in a "safe zone" without breaking the main, working version of your app.
Trace a culprit: You know exactly who changed what line of code and why.
If you are using VS code, you can use git lens extension. which tells you which person have changed the particular line of code.
3. The Three Areas of Git
To use Git, you must understand the "flow" of a file. It doesn't just save instantly; it moves through three stages:
Working Directory: Where you are currently typing and deleting code (Unsaved).
Staging Area (Index): A "prep zone." You tell Git, "I want these specific changes to be part of my next save."
Repository (.git folder): The permanent home where Git stores the history of your project.
4. Core Terminologies
Repository (Repo): Your project folder that Git is tracking.
Commit: A "snapshot" of your project at a specific point in time. Each commit has a unique ID.
Branch: A parallel version of your project. You might have a
mainbranch for the live site and afeature-loginbranch for a new task.Head: A pointer that tells you which branch or commit you are currently looking at.
5. Essential Git Commands
Here is the basic workflow you will use 90% of the time:
Starting a Project
git init
This creates a hidden .git folder. Your project is now being watched by Git.
Checking the Status
git status
This tells you which files have been changed and which ones are currently in the "Staging Area." Run this constantly!
Saving Changes
To save your work, you perform a two-step dance:
Add: Move files to the staging area.
git add index.htmlCommit: Permanently save that snapshot with a descriptive message.
git commit -m "Add a navigation bar to the homepage"
Viewing History
git log
This shows you a list of all your previous commits, who made them, and when.
6. A Simple Developer Workflow
Imagine you are building a website for Hariss International:
Initialize: You run
git initin your project folder.Code: You create a file called
contact.js.Stage: You run
git add contact.js.Commit: You run
git commit -m "Initial contact page layout".Experiment: You create a new branch called
red-button-testto see if a red button looks better.Merge: If you like it, you bring those changes back into your
mainbranch.
If you want to understand difficult commands, think of the commits as the node, and when you create new commit, it creates new node and new node is linked back to the previous node.
Now, you may have understood the git basics commands. Further you can learn commands which help us in undoing the work we have done (git checkout, git rebase). That’s it, see you on next blog.




